Try it Live
Run ABI examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see ABI API.
What is ABI?
ABI defines how to encode and decode data for contract interactions:- Function calls - Encode parameters into calldata
- Function returns - Decode return values from execution
- Events - Encode/decode log entries
- Errors - Encode custom error data
transfer(address,uint256) or parse Transfer events.
Function Selectors
Every function call starts with a 4-byte selector derived from the function signature:Why Selectors Matter
The EVM uses selectors to route function calls. Calldata format:transfer(0x742d..., 1000):
Encoding Rules
ABI encoding packs data into 32-byte words with specific alignment rules.Fixed-Size Types
Types with known size encode directly into 32-byte slots:- uint256
- address
- bool
- bytes32
Dynamic Types
Dynamic types (string, bytes, arrays) use offset-based encoding:- string
- bytes
- uint256[]
- Offset (32 bytes) - Where data starts relative to parameter start
- Length (32 bytes) - Number of bytes in data
- Data (padded to 32-byte multiple) - Actual content
Complete Function Call Example
Encode complete calldata fortransfer(address,uint256):
Decoding Return Values
Decode function return data after execution:Multiple Parameters
Mixed fixed and dynamic types require offset tracking:Encoding Layout
Constructor Encoding
Encode constructor parameters for contract deployment:Event Encoding
Events split data into indexed topics (for filtering) and non-indexed data (for details).Event Structure
Encoding Event Topics
Topic 0 is always the event signature hash:Decoding Event Logs
Parse log data and topics back to values:Why Indexed Parameters?
Indexed parameters become topics, enabling efficient filtering:Tuple Encoding
Tuples (structs) encode as grouped parameters:Array of Tuples
Visual Encoding Example
Encodingregister(address,string,uint256) with values:
- address:
0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e - string:
"alice" - uint256:
25
Common Use Cases
Calling Contract Functions
Parsing Event Logs
Handling Contract Errors
Type Safety
Tevm provides full TypeScript type inference:Error Handling
ABI operations can fail with specific error types:Resources
- Solidity ABI Specification - Official encoding specification
- Contract ABI Specification - JSON ABI format
- EIP-712 - Typed structured data hashing
- ABI Playground - Interactive encoder/decoder
Next Steps
- Overview - Type definitions and API reference

