Skip to main content
Here’s an example of how SDK packages can be combined into a working indexer (called squid). This page goes through all the technical details to make the squid architecture easier to understand. If you would like to get to a working indexer ASAP, bootstrap from a template.

USDT transfers API

Pre-requisites: NodeJS 20.x or newer, Docker.
Suppose the task is to track transfers of USDT on Ethereum, then save the resulting data to PostgreSQL and serve it as a GraphQL API. From this description we can immediately put together a list of packages:
  • @subsquid/evm-processor - for retrieving Ethereum data
  • the triad of @subsquid/typeorm-store, @subsquid/typeorm-codegen and @subsquid/typeorm-migration - for saving data to PostgreSQL
We also assume the following choice of optional packages:
  • @subsquid/evm-typegen - for decoding Ethereum data and useful constants such as event topic0 values
  • @subsquid/evm-abi and @subsquid/evm-codec - runtime dependencies imported by code generated by @subsquid/evm-typegen
  • @subsquid/graphql-server / OpenReader
To make the indexer, follow these steps:
1

Create a new folder and initialise a new project

  • create package.json
  • add .gitignore
    .gitignore
2

Install the packages

3

Add a minimal `tsconfig.json`

tsconfig.json
4

Define the schema for both the database and the core GraphQL API

Define the schema for both the database and the core GraphQL API in schema.graphql:
schema.graphql
5

Generate TypeORM classes based on the schema

The TypeORM classes are now available at src/model/index.ts.
6

Prepare the database

  • create .env and docker-compose.yaml files
    .env
    docker-compose.yaml
  • start the database container
  • compile the TypeORM classes
  • generate the migration file
  • apply the migration with
7

Generate utility classes for decoding USDT contract data

Generate utility classes for decoding USDT contract data based on its ABI.
  • Create an ./abi folder:
  • Find the ABI at the “Contract” tab of the contract page on Etherscan. Scroll down a bit:
  • Copy the ABI, then paste to a new file at ./abi/usdt.json.
  • Run the utility classes generator:
The utility classes are now available in src/abi/usdt/, with an index.ts entry point. Typegen v5 removes a stale src/abi/usdt.ts file from the older single-file layout.
8

Tie all the generated code together with `src/main.ts`

Tie all the generated code together with a src/main.ts executable with the following code blocks:
  • Imports
  • EvmBatchProcessor object definition
  • TypeormDatabase object definition
  • A call to processor.run() with an inline definition of the batch handler
    Note how supplying a TypeormDatabase to the function caused ctx.store to be a PostgreSQL-compatible Store object.
9

Compile the project and start the processor process

Compile the project and start the processor process
10

Start the GraphQL server

In a separate terminal, configure the GraphQL port and start the GraphQL server:
.env
The finished GraphQL API with GraphiQL is available at localhost:4350/graphql. Final code for this mini-tutorial is available in this repo.
The commands listed here are often abbreviated as custom sqd commands in squids. If you’d like to do that too you can use the commands.json file of the EVM template as a starter.