The Enjin Matrixchain Indexer is a Squid 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.
[!NOTE]
You can find a hosted version of this indexer available at Subsquid Aquarium in the following URL: https://squid.subsquid.io/matrixchain/graphql
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 18.x
- NPM
- Docker
- 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_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:
npx squid-substrate-metadata-explorer --rpc wss://archive.matrix.blockchain.io --out typegen/matrixVersion.jsonl
In this indexer we use all the metadata of Enjin Matrixchain and Canary Matrixchain so make sure you save them and use the proper WSS endpoint to gather them.
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:
npx squid-substrate-typegen typegen/typegen.json
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:
npx squid-typeorm-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:
npx squid-typeorm-migration generate
npx squid-typeorm-migration apply
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