This guide will help you set up and run a Subsquid-based indexer for a Substrate chain. The indexer tracks balance transfers and can be extended to track other events and calls.
- Node.js (v16 or later)
- Docker
- Install dependencies:
npm installInstall sqd command line
npm install -g @subsquid/cli- Create a
.envfile in the root directory with your RPC endpoint:
RPC_ENDPOINT=ws://localhost:9944 # For local node
# or
RPC_ENDPOINT=wss://your-testnet-endpoint # For testnet
- Generate types and code for your chain:
sqd typegen
sqd codegen
sqd buildInitialSchema1790849787837 replaces InitialSchema1790651935090. TypeORM records applied migrations by name, so a database from the previous migration still looks pending. sqd migration:apply and sqd run refuse to continue while indexer tables are already present. Drop that database and reindex. The processor rebuilds chain totals from chain history.
Clean reindex (required for a database created by an earlier migration):
sqd down
sqd up
sqd migration:apply
sqd runsqd down removes the local Postgres container. docker-compose-dev.yml does not mount a data volume, so the next sqd up is an empty database.
Resume when InitialSchema1790849787837 is already applied:
sqd up
sqd runStart the processor and GraphQL API:
sqd runIf you only want to start the processor but not the rest of the system, use this instead
sqd process- The processor configuration is in
src/processor.ts - The GraphQL schema is in
schema.graphql - The database migrations are in
db/migrations
- Tracks balance transfers
- Stores transfer amounts, fees, and account information
- Provides GraphQL API for querying the indexed data
This indexer also tracks the full lifecycle of reversible transfers:
- Scheduled: When a new reversible transfer is created.
- Executed: When a scheduled transfer is successfully completed.
- Cancelled: When a scheduled transfer is cancelled before execution.
The indexer creates or updates ReversibleTransfer entities in the database and creates a single Event entity when a transfer is first scheduled.
The GraphQL server provides a flexible API for querying the indexed data. Here are a few examples:
To add new events or calls to track:
- Update the processor configuration in
src/processor.ts - Update the GraphQL schema in
schema.graphql - Generate new migrations:
sqd migration:generateIf you encounter issues:
- Make sure Docker is running
- Check that your RPC endpoint is correct in
.env - Drop the database and reindex:
sqd down
sqd up
sqd migration:apply
sqd run- Install Subsquid CLI globally:
npm install -g @subsquid/cli- Initialize a new Subsquid project:
sqd init substrate-indexer --template substrate
cd substrate-indexerFor more detailed information about the project structure and advanced features, please refer to the original README in the substrate-indexer directory.
[Add your license information here]