Skip to main content

What Is the Difference between a Receive and a Fallback Function in Solidity?

The receive function is specifically executed when a transaction sends Ether to the contract with no data (empty calldata ). It must be declared as payable and cannot have arguments.

The fallback function is executed when a contract is called without matching any other function, or if it receives Ether with data. Both can be entry points for a reentrancy attack, but receive is specifically for plain Ether transfers.

What Are the Two Main Types of Interest Rate Swaps?
Why Are Fallback Functions Critical in a Reentrancy Scenario?
Can a Reentrancy Attack Be Performed without a Fallback Function?
How Do Modern Solidity Versions Recommend Handling Ether Transfers Instead of Using a Gas Stipend?