Solidity theorytheory 0/50 · 0%
ABI · medium

30. Function selectors and the ABI

How calldata identifies a function.

A call's first four bytes are the selector: the first four bytes of `keccak256("transfer(address,uint256)")`. Arguments follow, ABI-encoded in 32-byte words.

bytes4 sel = bytes4(keccak256("stake(uint256)"));
abi.encodeWithSelector(sel, amount);

Use `abi.encodeCall(IERC20.transfer, (to, amt))` when you can: it type-checks the arguments against the real signature.

Check your understanding

  1. 1. How long is a function selector?

  2. 2. What is hashed to produce it?

  3. 3. Why prefer `abi.encodeCall`?