Skip to main content

Overview

Event.decodeLog decodes a single log entry using a specific event definition. It validates topic0 for non-anonymous events and combines indexed topics with non-indexed data.

Quick Start

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

const Transfer = {
  type: 'event',
  name: 'Transfer',
  inputs: [
    { type: 'address', name: 'from', indexed: true },
    { type: 'address', name: 'to', indexed: true },
    { type: 'uint256', name: 'value' }
  ]
} as const;

const log = {
  data: '0x00000000000000000000000000000000000000000000000000000000000003e8',
  topics: [
    '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
    '0x000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f51e3e',
    '0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4'
  ]
};

const decoded = Abi.Event.decodeLog(
  Transfer,
  Hex.toBytes(log.data),
  log.topics.map(Hex.toBytes)
);
// { from: '0x742d...', to: '0x5b38...', value: 1000n }

Dynamic Indexed Parameters

When an indexed parameter is dynamic (string, bytes, dynamic arrays), the topic contains keccak256(value). The original value cannot be reconstructed from the topic alone.

Error Handling

  • AbiDecodingError when topics are missing or data is malformed
  • AbiInvalidSelectorError when topic0 does not match the event

See Also