Skip to main content
Indexers provide an easy solution to query on-chain data. They process smart contract events in the background and store them in a database, which you can query using GraphQL. This enables efficient access to all smart contract events and allows for filtering the data as needed.

Prerequisites

  • Node.js 20.x or later is installed.
  • Docker is installed, and you have basic knowledge of using it.

Instructions

Install Subquid

Create a Squid: Follow the instructions for creating a Squid.
  • During setup, create a new Squid with a name of your choice. This will be used later.

Create the Indexer

Initialize the JavaScript environment

Install required packages

Add tsconfig.json

Create a tsconfig.json file in your project root with the following configuration:

Define the schema

Create a schema.graphql file and define the database schema. For example:
This schema represents the structure of the events you want to store in your database.

Generate TypeORM entities

Run the following command to generate TypeORM entities based on the schema:

Create a .env file

Define the database credentials in a .env file:

Create docker-compose.yaml

Create a docker-compose.yaml file to set up a PostgreSQL database:
Start the database container:

Compile TypeORM classes

Compile the generated TypeORM classes:

Generate and apply migrations

  • Generate the migration file:
  • Apply the migration:

Tie the code together

Create a src/main.ts file and add the following code:

Compile and start the processor

  • Compile the code:
  • Start the processor:

Start the GraphQL server

In a separate terminal, start the GraphQL server: