Skip to content

Log

An event log as a node returns it: the contract that emitted it, its topics and data, and its place in the chain.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";
const TOKEN = Address.makeUnsafe("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2");
const emitters = Effect.gen(function* () {
const logs = yield* Eth.getLogs({ address: TOKEN, fromBlock: "finalized" });
// logs: ReadonlyArray<Log.Log>
return logs.map((log) => [log.blockNumber, log.transactionHash, log.topics[0]]);
});
Schema Type Describes Returned by
Log.schema Log.Log one log Eth.getLogs, Eth.getFilterChanges, Eth.getFilterLogs, Eth.subscribe.logs

A log is also what the logs of a Receipt hold, and the logs of a simulated call in Simulate.

Import the type to name it in your own signatures.

import type { Log } from "@ethect/core/rpc";
const isMined = (log: Log.Log): boolean => log.blockNumber !== null;
Field Type Notes
address Address the contract that emitted the log
topics ReadonlyArray<Hash> up to four: usually the hash of the event signature, then the indexed arguments
data Hex the arguments that are not indexed, ABI-encoded
blockHash Hash | null null on a pending log
blockNumber bigint | null null on a pending log
blockTimestamp bigint (optional) seconds since the Unix epoch, where the node sends it
transactionHash Hash | null null on a pending log
transactionIndex number | null the position of the transaction in its block
logIndex number | null the position of the log in its block
removed boolean (optional) true when a reorg dropped the block the log was in
  • Hex in, hex out. A log is as the node sent it: topics and data are hex. Ev.decode reads them as the events of a contract.
  • null means pending. The five position fields are null only while the transaction of the log is not mined. They are always present, so they are typed | null, not optional.
  • removed comes with a reorg. A log subscription pushes the logs of a dropped block a second time with removed: true. Elsewhere anvil sends false.
  • Optional means absent. blockTimestamp and removed are left out of the object when the node does not send them. anvil sends both.
  • Lowercase address. address is lowercase: Address.checksum gives the EIP-55 form.