@subsquid/batch-processor connects a Portal-compatible data source to a database and an asynchronous data handler. Use it with the EVM Portal stream or Solana Portal stream.
Development flow
Choose a database
Pass a Squid SDK database implementation such as
TypeormDatabase, or implement the database interfaces.run() and Processor
Both APIs use the same source, database, handler, and optional RunOptions object.
- Application entry point
- Awaitable runner
run() returns void. It installs top-level error handling and owns the processor process lifecycle, so it is intended for the main application entry point.Handler context
The handler receives this context:storeis supplied by the database transaction.blockscontains the current block slice.isHeadistruewhen the processor has reached the current source head.
ctx.log or ctx._chain. Create a logger or RPC client explicitly when the handler needs one.
Finalized and hot-block databases
The database determines which stream the processor consumes:| Database capability | Source method | Database transaction |
|---|---|---|
supportsHotBlocks is absent or false | getFinalizedStream() | transact() |
supportsHotBlocks: true | getStream() | transactHot2() |
Prometheus
Pass aPrometheusServer in the optional fourth argument to run(), or as the fourth Processor constructor argument:
PROCESSOR_PROMETHEUS_PORT takes precedence over PROMETHEUS_PORT. Metrics are disabled if neither variable is set.
Read a data source directly
The object returned by an EVM or SolanaDataSourceBuilder.build() implements these methods:
| Method | Result |
|---|---|
getHead() | Latest source head, including unfinalized blocks |
getFinalizedHead() | Latest finalized source head |
getStream(request) | Hot-block-aware asynchronous block batches |
getFinalizedStream(request) | Finalized asynchronous block batches |
getBlocksCountInRange?(range) | Optional block-count helper used for progress estimates |
from, optional to, and optional parentHash fields. Each yielded batch contains blocks and may contain finalizedHead.
run() or Processor when you need restart-safe indexing and hot-block rollback handling.