Fallback Function
A special function that executes when no other function matches a contract call.
Last Updated
2026-03-19
Related Concepts
What is Fallback Function?
A fallback function is a specialized, unnamed function in a Solidity smart contract that serves as a "catch-all." It automatically executes when a contract receives a call with data that does not match any of its existing function signatures.
How does Fallback Function work?
- A transaction is sent to a contract with a 4-byte "function selector."
- The EVM checks the contract's code for a function that matches that selector.
- If no match is found, the EVM automatically triggers the fallback function.
- If the contract also receives Ether but no data, it triggers the receive function (if defined); otherwise, it defaults to the fallback.
- Fallback functions have a very limited gas stipend (
2,300gas) if triggered by a simpletransferor send call.
Why does Fallback Function matter?
Fallback functions provide a safety net for contracts, allowing them to handle unexpected interactions gracefully rather than simply failing. They are also crucial for the "Proxy" pattern, where a contract forwards all unknown calls to another implementation contract to enable upgradeability.
Key features of Fallback Function
- Unnamed and can only have one per contract
- Executed when no other function matches the call
- Can be used to receive Ether (if marked payable)
- Essential for proxy and upgradeable contract patterns
- Must be written with strict security to prevent reentrancy
Examples of Fallback Function
Proxy contracts (like those used by Gnosis Safe or USDC) use a fallback function to take any incoming transaction and "forward" it to a different contract that contains the actual logic. This allows the main contract address to remain the same even when the logic is updated.
