Skip to main content

Try it Live

Run ABI examples in the interactive playground

Overview

Abi.parseLogs decodes a list of log entries using a full ABI. It matches non-anonymous events by topic0 and decodes indexed and non-indexed parameters. Logs that do not match any event are skipped.

Quick Start

import { Abi } from '@tevm/voltaire/Abi';

const abi = Abi([
  {
    type: 'event',
    name: 'Transfer',
    inputs: [
      { type: 'address', name: 'from', indexed: true },
      { type: 'address', name: 'to', indexed: true },
      { type: 'uint256', name: 'value' }
    ]
  },
  {
    type: 'event',
    name: 'Approval',
    inputs: [
      { type: 'address', name: 'owner', indexed: true },
      { type: 'address', name: 'spender', indexed: true },
      { type: 'uint256', name: 'value' }
    ]
  }
] as const);

// const logs = await provider.getLogs({ address: tokenAddress });
const decoded = abi.parseLogs(logs);

for (const log of decoded) {
  if (log.eventName === 'Transfer') {
    console.log('Transfer', log.args);
  }
}

Hex or Bytes Input

parseLogs accepts both hex strings and byte arrays:
const logs = [
  {
    data: '0x...',
    topics: ['0x...', '0x...', '0x...']
  }
];

const decoded = abi.parseLogs(logs);

Anonymous Events

Anonymous events omit topic0. parseLogs can decode them only when there is a unique anonymous event with the same number of indexed parameters.
const Anonymous = {
  type: 'event',
  name: 'Anonymous',
  anonymous: true,
  inputs: [
    { type: 'address', name: 'who', indexed: true }
  ]
} as const;
If multiple anonymous events share the same indexed count, parseLogs cannot disambiguate and will skip them.

Decode a Single Event

If you already know the event definition, decode directly:
import { Abi } from '@tevm/voltaire/Abi';

const decoded = Abi.Event.decodeLog(Transfer, log.data, log.topics);

Dynamic Indexed Parameters

Dynamic indexed parameters (like string or bytes) are stored as keccak256 hashes in topics. You can compare them, but you cannot recover the original value from the topic alone.

See Also