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]]);});Schemas
Section titled “Schemas”| 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;Fields
Section titled “Fields”| 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 |
Behavior
Section titled “Behavior”- Hex in, hex out. A log is as the node sent it:
topicsanddataare hex.Ev.decodereads them as the events of a contract. nullmeans pending. The five position fields arenullonly while the transaction of the log is not mined. They are always present, so they are typed| null, not optional.removedcomes with a reorg. A log subscription pushes the logs of a dropped block a second time withremoved: true. Elsewhere anvil sendsfalse.- Optional means absent.
blockTimestampandremovedare left out of the object when the node does not send them. anvil sends both. - Lowercase address.
addressis lowercase:Address.checksumgives the EIP-55 form.