The Enjin Blockchain Indexer is a Squid Indexer that serves processed blockchain data for other applications and dApps that require a more performant approach to retrieve the data as well as filtering, sorting, and relationships.
A squid is a project that extracts and transforms on-chain data in order to present it as a GraphQL API. Squids are developed using the Subsquid SDK, which provides extensive tooling to define data schemas, data transformation rules, and the shape of the resulting API.
We recommend that you read SubSquid docs to understand how it works: https://docs.subsquid.io/
- Node 20.x
- PNPM 8.x
- PostgreSQL 16.x
- Redis 7.x
Or you can use Docker with the provided docker-compose file to start all services.
- Clone the repository
- Run
docker compose up -d
- Access the GraphiQL Playground at http://localhost:4000/graphql
The indexer is composed of 4 containers
- indexer_db - a postgres database that stores the processed data;
- indexer_redis - a redis instance used for cache and queue;
- indexer_processor - the worker that transforms and saves the blockchain data;
- indexer_graphql - the GraphQL API that exposes the processed data;
- indexer_worker - the queue worker that processes the metadata of assets.
The chain metadata is used to generate the interface classes through typegen. To scan the blockchain and get the all the metadata ever used you can use the following command:
pnpm run metadata:fetch
This indexer works with all Enjin networks, so make sure you always save the metadata from all of them before generating the typegen.
The typegen tool is used for generating TypeScript interface classes for Substrate events, calls and storage. To generate it, first you should merge both metadata from Enjin Matrixchain and Canary Matrixchain into a single file. Then you can use the following command:
pnpm run metadata:typegen
The codegen tool is used for generating the model classes based on the GraphQL schema. If you edit the schema.graphql
you should regenerate it by running:
pnpm run schema:codegen
When the schema is changed we need to make a new migration. For development purposes the simplest way is to drop the database and generate the migrations from scratch. To do that, after you are finished editing the schema.graphql
file and have generated all model files. You might run:
pnpm run db:generate
pnpm run db:migrate
Please note: you need to delete the files under db/migrations
and your database must be clean before running the generate
command as this will connect to your database for checking the "changes" and generate the file based on it.
For simplifying the steps above when making a change to the schema, we have created a script that will do all the steps for you. Just run:
./refresh-db.sh