Cointegrity

Fallback Function

Web3 / smart contracts

A fallback function is a special, unnamed function in Ethereum smart contracts that automatically executes when the contract receives a call to a function selector it does not recognize or when someone sends ether directly to the contract without specifying a function. Defined with the `fallback()` keyword in Solidity, it allows developers to handle unexpected or generic transactions gracefully, often used for receiving payments, logging calls, or rejecting unwanted transfers. This mechanism ensures contracts can respond intelligently to any incoming transaction rather than reverting silently.

Example

Uniswap's router contract uses a fallback function to reject direct ether transfers that don't match standard swap or liquidity provision function signatures, protecting users from accidentally sending funds to incorrect function calls.

Why It Matters

Fallback functions provide essential error handling and flexibility in contract design, preventing locked or lost funds from incorrect transaction calls while enabling sophisticated multi-purpose contracts that can handle diverse interaction patterns and edge cases.

Category: smart contracts

Definition maintained by Cointegrity. See our editorial policy for review standards on regulatory and compliance terms.

Explore the full Web3 Glossary — 2,094+ expert-curated definitions. Need guidance? Talk to our consultants.