Lab: free tools · size first · stock scanner · crypto scanner · journal
ABI Encoding in Solidity and Ethereum: How Contract Calls Work
The Application Binary Interface (ABI) in Ethereum defines how function call data is encoded for smart contract interactions. ABI encoding converts function names, parameter types, and values into the hexadecimal calldata format that the EVM understands. Understanding ABI encoding is essential for smart contract development, debugging, MEV, and building low-level Ethereum tooling.
Every time a wallet calls a contract, the function name and arguments are packed into bytes the EVM can read: a four-byte selector taken from the hash of the function signature, then the arguments laid out in 32-byte slots. That packing is the ABI. You rarely see it until something breaks, like a wallet showing "unknown function" or a decoded transaction that looks nothing like what you meant to sign. Learning to read calldata is how you check what you are approving before you approve it.
Reading calldata by hand
Take an ERC-20 transfer. Its signature is transfer(address,uint256). Hash that with Keccak-256, keep the first four bytes, and you get the selector 0xa9059cbb. Next come two 32 byte slots: the recipient's address padded with zeros on the left, then the amount, also padded. The amount is counted in the token's smallest unit, so it looks far bigger than the number you typed. An approve call starts with 0x095ea7b3 and carries the same two slots, a spender and an amount.
Dynamic types
Strings, byte arrays and lists don't fit in one slot. For these the ABI puts an offset in the slot, pointing further along the calldata where the length and contents sit. Swaps through a router pass paths and other lists this way, which is why their calldata gets long and hard to read without a decoder.
Why it matters for safety
A call starting with 0x095ea7b3 whose amount is the largest possible number grants unlimited spending of that token. If that contract later gets exploited, the attacker can drain those tokens from your wallet. 0xa22cb465 is setApprovalForAll, which hands an operator every NFT you hold in a collection. Good wallets decode these, but when a wallet says it can't decode a call, paste the calldata into a decoder or block explorer before signing. Selectors are only four bytes, so two different functions can end up sharing one. Tools that guess function names from selector databases can be fooled that way, which is one more reason to check the contract address you're calling.