Solidity theorytheory 0/50 · 0%
Value · easy

16. Sending and receiving ETH

receive, fallback, transfer and call.

A contract can accept plain ETH transfers only if it has a `receive()` or a payable `fallback()`. To send, prefer `call` with an explicit success check, since `transfer` forwards a fixed 2300 gas that can break with smart-contract wallets.

receive() external payable {}

function payOut(address to, uint256 amount) internal {
    (bool ok, ) = to.call{value: amount}("");
    require(ok, "send failed");
}

Always write state before sending value, and check the returned boolean.

Check your understanding

  1. 1. Which function receives plain ETH with empty calldata?

  2. 2. Why prefer `call{value:}` over `transfer`?

  3. 3. What must you do with `call`'s return value?