Skill 2.2.2

Send and receive ether in contracts

Key Concepts

A contract receives plain ether (a transfer with empty calldata) through receive() external payable. If calldata does not match any function, or ether arrives with calldata and no receive exists, fallback() external payable runs. A contract with neither rejects plain ether transfers, and functions must be payable to accept ether in a call.

To send ether, the recommended form is (bool success, ) = recipient.call{value: amount}(""); followed by require(success) or a custom error. transfer reverts on failure and send returns false; both forward only a 2,300 gas stipend, which smart contract wallets often need to exceed, so they are discouraged. Because call forwards all remaining gas, the receiver can run code, so sending ether must follow the checks-effects-interactions pattern.