What is an ABI?
The Application Binary Interface (ABI) is the standard specification defining how to interact with a smart contract. It describes all contract functions, their parameters, return types, and events in a structured JSON format. The ABI serves as the bridge between human-readable function calls and the low-level bytecode that the EVM executes, enabling wallets, dApps, and scripts to correctly encode and decode contract interactions.
ABI Structure and Contents
An ABI document is a JSON array containing entries for each public function, event, error, and constructor in a contract. Each function entry specifies its name, input parameters (with names and types), output parameters, state mutability (pure, view, nonpayable, payable), and function type.
For example, an ERC-20 transfer function ABI entry includes the function name "transfer", inputs for recipient address (type address) and amount (type uint256), output type boolean, and state mutability "nonpayable". Events include indexed parameter specifications enabling efficient log filtering. Custom error definitions enable typed revert reasons.
Encoding and Decoding
When you call a smart contract function, your transaction data encodes the function selector (first 4 bytes of the keccak256 hash of the function signature) followed by ABI-encoded parameters. The ABI specification defines encoding rules: addresses as 32-byte right-padded values, integers as 32-byte values, dynamic types like strings and arrays with length prefixes.
Decoding works in reverse. Raw transaction data or return values are interpreted according to the ABI to produce human-readable values. Without the ABI, reading raw contract inputs and outputs would require manual bytecode analysis and guesswork.
ABI in Practice
DeFi developers use ABIs constantly when building frontends, writing scripts, or integrating with contracts. Libraries like ethers.js and viem accept ABIs to generate type-safe contract interfaces with autocomplete and type checking. Verified contracts on block explorers provide ABIs for public access, enabling anyone to interact programmatically.
When interacting with unverified contracts, the lack of ABI makes interaction risky. You cannot easily understand what functions exist or what they do. Some security tools can decompile bytecode to approximate ABIs, but this process is imperfect and loses semantic information.