Skip to main content

Try it Live

Run ABI examples in the interactive playground

Overview

ABI items represent contract interface elements. Four primary types:
  • Function - Contract methods (read/write)
  • Event - Log events emitted by contracts
  • Error - Custom error definitions (EIP-3668)
  • Constructor - Contract deployment parameters
Each type has specific encoding rules and selector generation.

Function Type

Functions define callable methods with inputs/outputs.
type AbiFunction = {
  type: 'function';
  name: string;
  inputs: AbiParameter[];
  outputs: AbiParameter[];
  stateMutability: 'pure' | 'view' | 'nonpayable' | 'payable';
};
Selector: First 4 bytes of keccak256(signature)

Event Type

Events define log structures for contract notifications.
type AbiEvent = {
  type: 'event';
  name: string;
  inputs: AbiParameter[];
  anonymous?: boolean;
};
Selector: Full 32 bytes of keccak256(signature) (topic0)

Error Type

Errors define revert reasons with typed parameters.
type AbiError = {
  type: 'error';
  name: string;
  inputs: AbiParameter[];
};
Selector: First 4 bytes of keccak256(signature)

Constructor Type

Constructor defines deployment parameters.
type AbiConstructor = {
  type: 'constructor';
  inputs: AbiParameter[];
  stateMutability: 'nonpayable' | 'payable';
};
No selector: Constructor has no selector (called during deployment)

Parameter Types

All types use AbiParameter for inputs/outputs:
type AbiParameter = {
  name: string;
  type: string;
  components?: AbiParameter[]; // For tuples
  indexed?: boolean; // Events only
};

Type Guards

Use Abi.Item.* methods to check types:
import * as Abi from 'tevm/Abi';

const item = abi[0];

if (Abi.Item.isFunction(item)) {
  // item is AbiFunction
}

See Also