SubQuery Developer Guide: How to Run an Indexer Node?
Video Tutorial:
https://youtu.be/QfNsR12ItnA
Introduction
Running an Indexer node is another option besides using Docker or hosting your project on SubQuery. It requires more time and effort, but it will enhance your understanding of how SubQuery works.
Database
Running an Indexer node on your infrastructure requires setting up a Postgres database.
You can install Postgres and ensure the version is 12 or higher. (https://www.postgresql.org/download/)
Install Subql/Node
To run a SubQuery node, you need to execute the following command:
npm install -g @subql/node
-g indicates a global installation, which means it will be located on OSX at:
/usr/local/lib/node_modules
Once installed, you can check the version with the following command:
> subql-node --version
0.19.1
Database Configuration
Next, you need to set the following environment variables:
export DB_USER=postgres
export DB_PASS=postgres
export DB_DATABASE=postgres
export DB_HOST=localhost
export DB_PORT=543
Of course, if you want to modify the above key values, please adjust accordingly.
Note that the env command will display the current environment variables, and this process only temporarily sets these values.
That is to say, they only apply to the terminal session.
To set them permanently, store them in your ~/bash_profile.
Indexing the Project
To start indexing a project, navigate to your project folder and run the following command:
subql-node -f
If you don't have a project yet, use:
git clone https://github.com/subquery/subql-helloworld
You should see the Indexer node start running and begin indexing blocks.
Check Postgres
If you navigate to Postgres, you should see two tables created.
public.subqueries and subquery1.starterentities.
public.subqueries contains only 1 row, which the indexer checks upon startup to "understand the current status" so it knows where to continue. The starterentities table contains the index. To view the data, run select (*) from subquery1.starter_entities.
Website:
https://www.subquery.network/
Discord Chinese Group:
https://discord.gg/ysdwnUSTQC
Telegram Chinese Group:
t.me/subquerychina
Mixin Chinese Group:
https://subquery.mixinbots.com/join