Substrate Processor Architecture
The processor service is a Node.js process responsible for data ingestion, transformation and data persisting into the target database. By convention, the processor entry point is atsrc/main.ts. It is run as:
.env using dotenv:
SubstrateBatchProcessor
The Squid SDK provides theSubstrateBatchProcessor class for indexing Substrate-based blockchains. By convention, the processor object is defined at src/processor.ts.
The SubstrateBatchProcessor is specifically designed for:
- Polkadot, Kusama, and other Substrate-based networks
- Processing events, calls, and extrinsics
- Runtime version-aware data decoding
- Efficient batch processing of blockchain data
Configuration
A processor instance should be configured to define the block range to be indexed, and the selectors of data to be fetched from SQD Network and/or a node RPC endpoint. Key configuration methods:setGateway()- Configure SQD Network data sourcesetRpcEndpoint()- Configure RPC data source (required for metadata)addEvent()- Request eventsaddCall()- Request callsaddExtrinsic()- Request extrinsicssetFields()- Select data fields
On Substrate, calling
setRpcEndpoint() is a hard requirement, as chain RPC is
used to retrieve chain metadata for proper data decoding.processor.run()
The actual data processing is done by the run() method called on a processor instance (typically at src/main.ts). The method has the following signature:
db parameter defines the target data sink, and batchHandler is an async void function defining the data transformation and persistence logic. It repeatedly receives batches of SQD Network data stored in context.blocks, transforms them and persists the results to the target database using the context.store interface.
Batch context
Batch handler takes a single argument ofDataHandlerContext type:
F is the type of the argument of the setFields() processor configuration method. Store type is inferred from the Database instance passed into the run() method.
ctx._chain
Internal handle for direct access to the underlying chain state via RPC calls. Rarely used directly, but rather by the facade access classes generated by the typegen tools.
ctx.log
The native logger handle. See Logger reference.
ctx.store
Interface for the target data sink. See Persisting data.
ctx.blocks
On-chain data items are grouped into blocks, with each block containing a header and iterables for all supported data item types. Boundary blocks are always included into the ctx.blocks iterable with valid headers, even when they do not contain any requested data. It follows that batch context always contains at least one block.
For Substrate, each block provides the following iterables:
block.events- Runtime events emitted during block executionblock.calls- Runtime calls (dispatchables) executed in the blockblock.extrinsics- Signed or unsigned extrinsics included in the block
.setFields() method.
An idiomatic use of the context API is to iterate first over blocks and then over each iterable of each block:
The canonical ordering of
ctx.blocks enables efficient in-memory data
processing. For example, multiple updates of the same entity can be compressed
into a single database transaction.ctx.isHead
Is true if the processor has reached the chain head. The last block in ctx.blocks is then the current chain tip.
Substrate-specific features
Runtime versions
Substrate chains can upgrade their runtime, changing the structure of events, calls, and storage. TheSubstrateBatchProcessor is aware of runtime versions and uses the typegen tools to generate runtime version-aware decoders.

