Setting up an Indexer
SubQuery is a fast, flexible, and reliable open-source data decentralised infrastructure network, providing both RPC and indexed data to consumers around the world.
In this guide, we will walk through the steps required to set up an indexer using SubQuery on AssetChain.
Prerequisites
Before starting, ensure the following tools are installed on your machine:
Node.js: Install Node.js (LTS version recommended) from the official site.
Docker: Required for running SubQuery locally. Install from the Docker website.
SubQuery CLI: Install using the command
Getting Started
Once you're done installing the Subquery CLI, Initialize a new Subquery project. Run the following command inside the directory that you want to create a SubQuery project in:
You'll be asked certain questions as you proceed ahead:
Project Name: Choose a name for your SubQuery project.
Network Family: Select the EVM . Use the arrow keys to browse the available options (there may be multiple pages to scroll through).
Network: Pick the specific network(i.e
Asset Chain Testnet
) to be indexed by this SubQuery project. Use the arrow keys to scroll through the available networks.Template Project: Select a template project to kickstart the development process(
asset-chain-testnet-starter
).RPC Endpoint: Provide the HTTP or websocket URL for a running RPC endpoint. This can be a public endpoint, a private node, or the default endpoint. Ensure the node has the full state of the data you wish to index—archive nodes are recommended.
Git Repository: Enter the Git URL for the repository where your SubQuery project will be hosted.
Authors: Specify the owner or author of this project (e.g., your name) or use the default provided.
Description: Write a brief description explaining the data your project indexes and what users can do with it, or use the provided default.
Version: Enter a custom version number or keep the default.
License: Provide a software license for the project or leave it as the default (MIT).
Let's look at an example
Finally, run the following command to install the new project’s dependencies from within the new project's directory
You have now initialised your first SubQuery project with just a few simple steps. Let’s now customise the asset-chain-testnet template for our project.
Building the Project
For this Project, we are going to be indexing this MultitokenLauncher Contract. Specifically, we will be indexing the TokenCreated
Event.
Inside your Project, you abis
directory and rename the erc20.abi.json
file to multitokenlauncher.abi.json
and replace the file content with this content below
We will edit the SubQuery project by changing the following files:
The project manifest in
project.ts
defines the key project configuration and mapping handler filtersThe GraphQL Schema (
schema.graphql
) defines the shape of the resulting data that you are using SubQuery to indexThe Mapping functions in
src/mappings/
directory are typescript functions that handle transformation logic
In the schema.graphql
file, replace the content with this:
In the mappings/mappingHandlers.ts
file, replace the content with this:
In the project.ts
file, replace the content with this:
Afterwards , Then Open your terminal and run the following code below
This Generates types from the GraphQL schema definition and contract ABIs and saves them in the /src/types
directory. This must be done after each change to the schema.graphql
file or the contract ABIs and Updating the project.ts
file.
Update mappings/mappingHandlers.ts
file with this content below:
Now that our Project is Completed, we need to build out the dist
file and test it.
in your terminal, run the following command:
Once the Build Passes, Kudos your Subgraph Project is Ready.
Testing
You need to test the project locally and make sure it is working before deploying.
To Test, make sure you have your Docker Environment is running.
in your terminal, run the following commands:
Open your Browser and Navigate to this URL http://localhost:3000/
query the graphql using the code below to get all Tokens created
to get a a Single Token created,
You should see the different output of this project in Browser.
Deploying our Subquery Project
Before you deploy your subquery project, you need to publish it first on the network.
Prepare your SUBQL_ACCESS_TOKEN
Step 1: Go to SubQuery Managed Service and log in.
Step 2: Click on your profile at the top right of the navigation menu, then click on Refresh Token.
Step 3: Copy the generated token.
Step 4: To use this token:
Add SUBQL_ACCESS_TOKEN in your environment variables.
EXPORT SUBQL_ACCESS_TOKEN=<token>
(Windows) orexport SUBQL_ACCESS_TOKEN=<token>
(Mac/Linux)
Publish your project
In your project directory, run the following command
you should then see a similar output below
Deploying Our Project to The Network
To create your first project, head to SubQuery Managed Service. You'll need to authenticate with your GitHub account to login.
SubQuery Projects is where you manage all your hosted projects uploaded to the SubQuery platform. You can create, delete, and even upgrade projects all from this application.
Click on the Create Project
Buttton to Create your Project, A Modal will pop up, then you Click on the Subquery Project
and click the Next Button.
and then follow the steps and enter the following:
The information you are filling should tally with the same information you used while setting up the project using the CLI
Project Name: Name your project.
Description: Provide a description of your project.
Database: Premium customers can access dedicated databases to host production SubQuery projects from. If this interests you, you can contact sales@subquery.network to have this setting enabled.
Visible in Explorer: If selected, this will show the project from the public SubQuery explorer to share with the community.\
Below is the final code for our indexer project
Last updated