Events (Ev)
Events of a contract. Each one is a class whose instances are its decoded logs. Events are decoded from the logs of a receipt, asked for over a range of blocks, or watched as they happen.
import { Abi, Ev } from "@ethect/core";import type { Receipt } from "@ethect/core/rpc";
// event Transfer(address indexed from, address indexed to, uint256 value)class Transfer extends Ev.make("Transfer", { from: Abi.indexed(Abi.address), to: Abi.indexed(Abi.address), value: Abi.uint256,}) {}
// the transfers of a transaction, from its receiptconst transfers = (receipt: Receipt.Receipt) => Ev.decode(Transfer, receipt.logs).map((event) => [event.from, event.to, event.value]);| Export | Kind | Description |
|---|---|---|
Ev.make(name, fields) |
function | An event: a class to extend. Its indexed fields are those marked with Abi.indexed. |
Ev.decode(events, logs) |
function | Decodes logs in one pass: as one list in the order of the logs, or sorted by event when given a record. |
Ev.logs(events, filter?) |
function | Past events, in one array. |
Ev.watch(events, options?) |
function | Events as they happen, as a Stream. With fromBlock, the past ones first. |
Ev.pages(events, options?) |
function | Past then live, one range of blocks at a time. Each page says where it ends. |
Ev.Source |
reference | How logs arrive. The default picks from what the transport can do. |
Ev.subscription |
source | eth_subscribe: pushed by the node. |
Ev.filter |
source | eth_newFilter, then eth_getFilterChanges at every interval. |
Ev.polling |
source | eth_getLogs for each new block, by its hash. |
Ev.Emitted |
type | What every decoded event carries: log, where it comes from. |
Ev.Log |
type | A log that is in a block: its block, its transaction and its index are never null. |
Ev.Any |
type | Any event class. |
Ev.Events |
type | One event, or several. |
Ev.Of<E> |
type | What the events decode to: an instance of one of them. |
Ev.Filter<E> |
type | Which logs to ask for: address, args, fromBlock, toBlock. |
Ev.WatchOptions<E> |
type | A filter without toBlock, with confirmations and interval. |
Ev.Page<E> |
type | The events of a range of blocks: fromBlock, toBlock, hash, events. |
Under the hood
Section titled “Under the hood”Only the node is asked. Each function has its requests on its page.
Ev.logs(events, filter)- your node
eth_getLogs({ address, topics, fromBlock, toBlock })the range, in pieces when the node refuses it whole
- your node
Ev.watch(events)- your node
eth_subscribe("logs")over a transport that pushes - your node
eth_newFilterotherwise, theneth_getFilterChanges - your node
eth_getLogswhere the node has no filterat each block
- your node
Ev.pages(events, options)- your node
eth_getLogs({ address, topics, fromBlock, toBlock })the past, range by range - your node
eth_getLogs({ address, topics, blockHash })the head, block by blockat each new block
- your node
Ev.decode(events, logs)- your programno request: the logs are the ones you give