Skip to content

Log.fromRpc

Converts a Log.Rpc to an Log.Log.

Imports

Named
import { Log } from 'ox'

Examples

import { Log } from 'ox'
 
const log = Log.fromRpc({
  address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
  topics: [
    '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
    '0x0000000000000000000000000000000000000000000000000000000000000000',
    '0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1',
    '0x000000000000000000000000000000000000000000000000000000000000025b',
  ],
  data: '0x',
  blockHash:
    '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
  blockNumber: '0x12d846c',
  transactionHash:
    '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
  transactionIndex: '0x91',
  logIndex: '0x10f',
  removed: false,
})
{
address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
blockHash: '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
blockNumber: 19760236n,
data: '0x',
logIndex: 271,
removed: false,
topics: [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1",
"0x000000000000000000000000000000000000000000000000000000000000025b",
'0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
transactionIndex: 145,
}

End-to-end

Below is an example of how to use Log.fromRpc to instantiate a Log.Log from an RPC log.

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,
}

Definition

function fromRpc<log, pending>(
  log: log | Rpc<boolean>,
  _options?: fromRpc.Options<pending>,
): Log<pending>

Source: src/Log.ts

Parameters

log

  • Type: log | Rpc<boolean>

The RPC log to convert.

Return Type

An instantiated Log.Log.

Log<pending>