@subsquid/batch-processor connects a Portal-compatible data source to a database and an asynchronous data handler. Use it with a Portal-native chain-specific DataSourceBuilder.
Development flow
1
Build a data source
Configure a chain-specific The SQD Network gateway reads your data API key from the
DataSourceBuilder, then call build().SQD_API_KEY environment variable.2
Choose a database
Pass a Squid SDK database implementation such as
TypeormDatabase, or implement the database interfaces.3
Run the data handler
Use
run() for a normal processor entry point. Use Processor when the caller needs to await completion or handle an error itself.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:
See Custom Database for the full transaction contracts.
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 a Portal-nativeDataSourceBuilder.build() implements these methods:
A stream request has
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.