V2 gateway requests require an API key. Set SQD_API_KEY in .env before running gateway-based examples, or pass apiKey: process.env.SQD_API_KEY in GatewaySettings.
SubstrateBatchProcessor follows the common squid processor architecture, in which data processing happens within the batch handler, a function repeatedly called on batches of on-chain data. The function takes a single argument called “batch context”. Its structure follows the common batch context layout, with ctx.blocks being an array of Block objects containing the data to be processed, aligned at the block level.
For SubstrateBatchProcessor the Block interface is defined as follows:
F here is the type of the argument of the setFields() processor method.
The handler context also exposes ctx.log and ctx._chain.rpc. Use the RPC
property for direct JSON-RPC calls. Derive selected fields with
SubstrateBatchProcessorFields<typeof processor>.
Block.header contains the block header data. The rest of the fields are iterables containing four kinds of blockchain data. The canonical ordering within each iterable is the same as it is within the blocks.
The exact fields available in each data item type are inferred from the setFields() call argument. They are documented on the Field selection page:
Example
The handler below simply outputs all the Balances.transfer_all calls on Kusama in real time:
One can experiment with the setFields() argument and see how the output changes.