ABI Encoding Overview
The Contract ABI (Application Binary Interface) defines how to encode function calls and data. Every parameter is encoded to exactly 32 bytes (256 bits), with specific rules for different types.Encoding Structure
Basic Type Encoding
Integers (uint/int)
Integers are left-padded with zeros to 32 bytes:Addresses
Addresses are 20 bytes, left-padded to 32 bytes:Booleans
Booleans encoded asuint256:
false→0x0000...0000true→0x0000...0001
Fixed-Size Bytes (bytes1-bytes32)
Fixed bytes are right-padded with zeros:Dynamic Type Encoding
Dynamic types (strings, bytes, arrays) use offset-based encoding:- Static section contains offset pointer (32 bytes)
- Offset points to start of dynamic data
- Dynamic data starts with length, followed by content
Dynamic Bytes
Strings
Strings encoded identically tobytes:
Arrays
Fixed-Size Arrays
Fixed arrays encoded like multiple static parameters:Dynamic Arrays
Dynamic arrays use offset + length + elements:Complex Encoding
Multiple Parameters
With multiple parameters, dynamic types use offsets relative to start of parameters section:Structs (Tuples)
Structs encoded as if all fields were separate parameters:Nested Arrays
Arrays of dynamic types require nested offsets:Manual Encoding (Zig)
- Simple Function
- With Dynamic Data
Encoding Rules Summary
| Type | Size | Padding | Notes |
|---|---|---|---|
uint<N> | 32 bytes | Left (zeros) | N ∈ [8, 256] step 8 |
int<N> | 32 bytes | Left (sign-extended) | Negative values |
address | 32 bytes | Left (zeros) | 20-byte value |
bool | 32 bytes | Left (zeros) | 0 or 1 |
bytes<N> | 32 bytes | Right (zeros) | N ∈ [1, 32] |
bytes | Variable | Right (zeros) | Offset + length + data |
string | Variable | Right (zeros) | UTF-8 encoded |
T[] | Variable | - | Offset + length + elements |
T[k] | k × 32 bytes | - | Fixed array inline |
tuple | Sum of fields | - | Encoded as struct |
Decoding Process
Decoding reverses the encoding:- TypeScript
- Zig
Validation
Always validate encoded calldata:Gas Optimization Tips
- Use smaller types:
uint96instead ofuint256when possible - Minimize dynamic data: Fixed arrays cheaper than dynamic
- Pack structs: Group small values to reduce padding
- Order parameters: Put dynamic types last to simplify offsets
See Also
- Fundamentals - How the EVM processes calldata
- Decoded Form - CallDataDecoded structure
- Usage Patterns - Common patterns
- Abi - ABI encoding and decoding utilities

