What you’ll get
Your Substrate indexer (squid) will:- Fetch all historical KSM transfers on Kusama
- Save the data to a local PostgreSQL database
- Start a GraphQL server with a rich API to query the indexed transfers
This tutorial focuses on Substrate. For other chains, see the EVM Quickstart or Solana Quickstart.
Prerequisites
Before you begin, ensure you have:- Node.js v20+ - Download here
- Git - Download here
- Docker - Download here (for running PostgreSQL)
- WSL (Windows only) - Install WSL
1
(Optional) Install Squid CLI
Install the Squid CLI globally:
Verify installation by running
sqd --version2
Scaffold the indexer project
Create a new squid project from the or, if you skipped the installation of Squid CLI
substrate template:3
Inspect the project structure
Explore the project structure:Next, See the full file for details.
hello-squid
db
scripts
src
main.ts
model
generated
index.ts
processor.ts
types
.env
.squidignore
commands.json
docker-compose.yml
package.json
schema.graphql
squid.yaml
tsconfig.json
typegen.json
src/processor.ts: the data retrieval configuration.src/main.ts: the main executable, with the processing logic.src/types/: modules generated fromtypegen.jsonfor interfacing thebalancespallet data.src/model/: TypeORM model classes used in database operations. The classes insrc/model/generated/are generated fromschema.graphql.
processor.ts file defines the SubstrateBatchProcessor object and configures data retrieval:processor.ts
main.ts defines the data processing and storage logic. Data processing is defined in the batch handler, the callback that the processor.run() main call receives as its final argument:main.ts
4
Install dependencies and build
Install dependencies and build the project:
Verify the build completed successfully by checking for the
lib/ directory.5
Start the database and processor
The processor continuously fetches data, decodes it, and stores it in PostgreSQL. All logic is defined in First, start a local PostgreSQL database (the template includes a Docker Compose file):Apply database migrations:Then start the processor:
main.ts and is fully customizable.Add your SQD Network API key to .env before starting the processor:The indexer is now running and will begin processing blocks.
6
Start the GraphQL API
Start the GraphQL API to serve the transfer data:
7
Query the data
You can now query your indexed data! Check it out at the GraphiQL playground at localhost:4350/graphql.