Skip to content

Log

Utilities & types for working with Logs as defined in the Execution API specification

Examples

Converting from RPC Format

Logs can be converted from their RPC format using Log.fromRpc:

import 'ox/window'
import { AbiEvent, Hex, Log } from 'ox'
 
const transfer = AbiEvent.from(
  'event Transfer(address indexed from, address indexed to, uint256 indexed value)',
)
 
const { topics } = AbiEvent.encode(transfer)
 
const logs = await window.ethereum!.request({
  method: 'eth_getLogs',
  params: [
    {
      address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
      fromBlock: Hex.fromNumber(19760235n),
      toBlock: Hex.fromNumber(19760240n),
      topics,
    },
  ],
})
 
const log = Log.fromRpc(logs[0])
{
address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
blockHash: '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
blockNumber: 19760236n,
data: '0x',
logIndex: 271,
removed: false,
topics: [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1",
"0x000000000000000000000000000000000000000000000000000000000000025b",
'0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
transactionIndex: 145,
}

Functions

NameDescription
Log.fromRpcConverts a Log.Rpc to an Log.Log.
Log.toRpcConverts a Log.Log to a Log.Rpc.

Types

NameDescription
Log.LogA Log as defined in the Execution API specification.
Log.RpcAn RPC Log as defined in the Execution API specification.