Skip to main content
@subsquid/batch-processor connects a Portal-compatible data source to a database and an asynchronous data handler. Use it with the EVM Portal stream.

Development flow

1

Build a data source

Configure a chain-specific DataSourceBuilder, then call build().
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.
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.
The constructor signature is:

Handler context

The handler receives this context:
  • store is supplied by the database transaction.
  • blocks contains the current block slice.
  • isHead is true when the processor has reached the current source head.
Portal-native handlers do not receive 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 a PrometheusServer in the optional fourth argument to run(), or as the fourth Processor constructor argument:
Without an explicit server, 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-native DataSourceBuilder.build() implements these methods: A stream request has from, optional to, and optional parentHash fields. Each yielded batch contains blocks and may contain finalizedHead.
Direct iteration does not persist progress or open database transactions. Use run() or Processor when you need restart-safe indexing and hot-block rollback handling.