Blockchain & Cryptocurrency Glossary

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • search-icon Clear Definitions
  • search-icon Practical
  • search-icon Technical
  • search-icon Related Terms

Fallback Function

1 min read
Pronunciation
[fôl-bak fungk-shun]
Analogy
Think of the fallback function as a shopkeeper’s default clerk—when a customer arrives with an unrecognized request, the clerk handles it in a generic way.
Definition
A special Solidity function without name or arguments that is executed when a contract receives Ether without data or when no other function matches the call signature.
Key Points Intro
Fallback functions provide a catch‑all mechanism in smart contracts via:
Key Points

Unnamed function: Declared as `fallback()` with external visibility.

Payable or not: Must be marked `payable` to receive Ether.

Gas stipend: Limited gas when called via `.send` or `.transfer`.

No arguments/return: Cannot accept data or return values.

Example
A contract implements `fallback() external payable { emit Received(msg.sender, msg.value); }` to log unexpected Ether transfers.
Technical Deep Dive
The fallback function is invoked if calldata is empty and no `receive()` exists, or if calldata does not match any function selector. It shares a 2300‑gas stipend when called via `transfer`/`send`, sufficient only for logging or simple state changes. Defining logic here can catch erroneous calls or implement proxy forwarding.
Security Warning
Complex logic in fallback can enable reentrancy attacks due to inadvertent external calls; keep it minimal and use `ReentrancyGuard` where needed.
Caveat
Fallback functions have strict gas limits and can fail silently if over‑consuming gas.

Fallback Function - Related Articles

No related articles for this term.