Skip to main content
This tutorial builds a Substrate squid that indexes three kinds of Crust activity:
  • files added to or deleted from storage worker reports;
  • storage orders placed by accounts;
  • storage groups joined by accounts.
The example uses a bounded historical range so you can reproduce the result and let the processor exit cleanly.

Prerequisites

1

Scaffold the project with the latest CLI

Install the latest Squid CLI, then create a project from the Substrate template:
Install the template dependencies and update the packages used in this tutorial to their latest releases:
2

Configure gateway and RPC access

Add your SQD Network API key and the Crust RPC URL to .env:
The API key authenticates requests to the v2 SQD gateway. The processor uses the RPC endpoint to obtain chain metadata.
3

Define the entities

Replace schema.graphql with the following schema:
schema.graphql
Generate the TypeORM entity classes:
4

Generate current Crust event types

Replace typegen.json with this configuration:
typegen.json
Run Substrate typegen:
The generated wrappers reflect the actual Crust runtime types for each event.
5

Configure the processor

Replace src/processor.ts with the following code:
src/processor.ts
Selecting call.args is required because the added and deleted file lists belong to the Swork.report_works call. The bounded range contains all three requested event types.
To follow the chain continuously, remove the upper to bound and .setRpcDataIngestionSettings({disabled: true}). Keep a reliable RPC endpoint configured for real-time ingestion.
6

Decode and persist each event

Replace src/main.ts with this batch handler:
src/main.ts
The generated byte values, including fileCid, are already hex strings. They do not need another toHex() conversion.
7

Build and prepare PostgreSQL

Build the project, start PostgreSQL, replace the template migration, and apply the new migration:
8

Run and verify the processor

Start the processor:
The processor exits after block 589350. Query the stored row counts:
This range produces 181 accounts, 178 group joins, 6 storage orders, and 1 work report containing a file change.
9

Query the GraphQL API

Start the GraphQL server:
Open localhost:4350/graphql and run: