EVM Calldata Encoding
EVM Calldata Encoding: How It Works Under the Hood
EVM Calldata Encoding
EVM Calldata Encoding: How It Works Under the Hood
When interacting with smart contracts on the Ethereum Virtual Machine (EVM), every function call is ultimately translated into calldata — a low-level byte array that the EVM can understand. Understanding how calldata encoding works is essential for Blockchain developers, auditors, and anyone building or debugging EVM-based systems.
This article walks through the technical process of EVM calldata encoding, step by step, with concrete examples.
What Is EVM Calldata?
Calldata is a read-only byte array passed to a smart contract when a transaction or call is executed. It contains:
- A 4-byte function selector
- ABI-encoded function parameters
Calldata is used for:
- External function calls
- Contract-to-contract interactions
- Low-level calls (
call,delegatecall,staticcall)
Encoding Calldata — Step 1: Function Selector
The first 4 bytes of calldata identify which function is being called.
The selector is computed as:
keccak256("functionName(type1,type2,...)")[0:4]
Example for an ERC20 transfer:
transfer(address,uint256)
Python example:
from eth_utils import keccak
signature = b"transfer(address,uint256)"
selector = keccak(signature)[:4]
print(selector.hex())
Outsput:
a9059cbb
Step 2: ABI Encoding of Parameters
After the selector, parameters are encoded according to the Ethereum ABI specification.
Rules to remember:
- All values are encoded in 32-byte (256-bit) slots
- Static types (uint, address, bool) are encoded directly
- Dynamic types (bytes, string, arrays) use offsets
Example Parameters
to = 0x1111111111111111111111111111111111111111
amount = 1000000000000000000
Python example using eth_abi:
from eth_abi import encode
encoded_params = encode(
["address", "uint256"],
["0x1111111111111111111111111111111111111111", 10**18]
)
print(encoded_params.hex())
Step 3: Constructing the Final Calldata
Final calldata is simply:
calldata = function_selector + encoded_parameters
Python example:
calldata = selector + encoded_params
print("0x" + calldata.hex())
This 0x-prefixed hex string is what gets sent in a transaction’s data field.
Using a Calldata Encoder Tool
To avoid manual errors, you can use a dedicated Calldata encoder designed for EVM developers — https://toolsnest.dev/calldata-encoder
The tool lets you:
- Input a function signature
- Encode parameters correctly according to the ABI
- Handle tuples and arrays
- Generate calldata instantly in the browser
메타데이터
- post_id
- b6ea087d3c83
- slug
- evm-calldata-encoding-b6ea087d3c83
- url
- https://medium.com/@itay.opl/evm-calldata-encoding-b6ea087d3c83
- canonical_url
- https://medium.com/@itay.opl/evm-calldata-encoding-b6ea087d3c83
- author_url
- https://medium.com/@itay.opl
- status
- ok
- fetched_at
- 2026-08-06 05:40:07