一键导入
indexer-blocks
// Use when processing every block (or every Nth block) for time-series data, periodic snapshots, or block-level aggregations. indexer.onBlock API, where filter with block-number range and stride, and block handler context.
// Use when processing every block (or every Nth block) for time-series data, periodic snapshots, or block-level aggregations. indexer.onBlock API, where filter with block-number range and stride, and block handler context.
Use when something is unclear, confusing, or not covered by other skills. Search and read the latest Envio documentation without leaving the terminal.
Use when writing or editing config.yaml. Chain/contract structure, addresses, start_block, event selection, field_selection, custom event names, env vars, address_format, schema/output paths, YAML validation, and deprecated options.
Use when making RPC calls, fetch requests, or any external I/O from handlers. Effect API with createEffect, S schema validation, context.effect(), preload optimization (handlers run twice), cache and rateLimit options.
Use when indexing contracts deployed by factory contracts at runtime. contractRegister API, dynamic contract config (no address), async registration, and same-block event coverage.
Use when filtering events by indexed parameters to reduce processing volume. The `where` option supports static filters, dynamic per-chain functions, contract address filtering, and conditional enable/disable.
Use when writing or editing event handlers. Handler registration, context API (entity CRUD, getWhere queries, chain, log), spread updates, indexer runtime API, and common pitfalls.
| name | indexer-blocks |
| description | Use when processing every block (or every Nth block) for time-series data, periodic snapshots, or block-level aggregations. indexer.onBlock API, where filter with block-number range and stride, and block handler context. |
| metadata | {"managed-by":"envio"} |
Process every block (or every Nth block) using indexer.onBlock. No contract
address or config.yaml entry needed.
Branch by chain.id with a switch so the type system flags any
unconfigured chain via the default: never exhaustiveness check:
import { indexer } from "envio";
indexer.onBlock(
{
name: "BlockTracker",
where: ({ chain }) => {
switch (chain.id) {
case 1:
return { block: { number: { _gte: 18000000, _every: 100 } } };
case 8453:
return { block: { number: { _every: 50 } } };
default: {
// Exhaustiveness check: TypeScript errors here if a new chain ID
// is added to config.yaml but not handled above.
const _exhaustive: never = chain.id;
return false;
}
}
},
},
async ({ block, context }) => {
context.BlockSnapshot.set({
id: `${block.number}`,
blockNumber: BigInt(block.number),
});
}
);
| Option | Type | Required | Description |
|---|---|---|---|
name | string | yes | Handler name for logging |
where | ({ chain }) => boolean | filter | no | Predicate evaluated once per configured chain at registration. Return false to skip a chain, true / omit to match every block, or {block: {number: {_gte?, _lte?, _every?}}} to restrict range and stride. _every aligns relative to _gte, preserving (blockNumber - _gte) % _every === 0. |
indexer.onBlock API; filter is keyed by block.height instead of block.number.indexer.onSlot; filter shape is {slot: {_gte?, _lte?, _every?}} and the handler arg is {slot: number, context} (no block wrapper).indexer.onBlock self-registers — no config.yaml entry neededwhere returns false for every configured chain, a warning is logged at registration timeindexer.onEvent with where.block.number._gte (see indexer-filters). Event filters accept _gte only; _lte/_every are reserved for onBlock.If something is unclear, use the
envio-docsskill to search and read the latest documentation.