The Graph

Overview

Why Graph is needed?

The Graph is a decentralized protocol for indexing and querying data from blockchains.
The Graph makes querying fast, reliable and secure but also allows anyone to build and publish application programming interfaces (APIs) called subgraphs, which act as intermediaries and allow two applications to communicate with each other.

Prerequisites

Before you run The Graph node in a server, you must install:
  • Docker : Containerization platform for software solutions
  • Docker-compose : Used to automate interactions between docker containers
  • JQ : JSON processor for graph requests
In this guide, you will learn how to run an Astar node for getting more insight into the transactions of blockchain, providing indexing data to The Graph node.

One-line startup script

If one wants to finish the process without explanation, here is the one-line script for you. if you face an error upon execution, the descriptions below will help you to find where it needs to be adjusted. This script supposes that the running computer has installed all prerequisites.
Astar
Shiden
Shibuya
1
sudo curl -s <https://raw.githubusercontent.com/AstarNetwork/Astar/rpc-script/scripts/graph.sh> > graph.sh \
2
&& sudo bash ./graph.sh \
3
-chain astar \
4
-rpc-url <RPC URL>
Copied!
1
sudo curl -s <https://raw.githubusercontent.com/AstarNetwork/Astar/rpc-script/scripts/graph.sh> > graph.sh \
2
&& sudo bash ./graph.sh \
3
-chain shiden \
4
-rpc-url <RPC URL>
Copied!
1
sudo curl -s <https://raw.githubusercontent.com/AstarNetwork/Astar/rpc-script/scripts/graph.sh> > graph.sh \
2
&& sudo bash ./graph.sh \
3
-chain shibuya \
4
-rpc-url <RPC URL>
Copied!

Running Graph node

After successfully running an RPC node, The Graph node needs to be installed and configured for Shiden to connect to a separate computer. If you are running a self-signed RPC node, you need to set up an extra environment variable for allowance.
The first step is to clone the Graph Node repository:
1
git clone <https://github.com/graphprotocol/graph-node/> \\
2
&& cd graph-node/docker
Copied!
Next, execute the setup.sh file. This will pull all the necessary Docker images and write the necessary information in the docker-compose.yml file. Make sure you have docker-compose and jq are installed.
1
sudo bash ./setup.sh
Copied!
After running the command, the tail end of the command should show similar logs as below:
Once everything is set up, you need to modify the "Ethereum environment" inside the docker-compose.yml file, so that The Graph node points to the endpoint of the RPC that you are connecting with. Note that the setup.sh file detects RPC's Host IP and writes its value, so you'll need to modify it accordingly.

Modifying Ethereum environment

Astar
Shiden
Shibuya
1
# open docker-compose.yml
2
nano docker-compose.yml
3
4
# modify file and save
5
ethereum: 'astar:https://<IP address or domain>:<PORT>'
Copied!
1
# open docker-compose.yml
2
nano docker-compose.yml
3
4
# modify file and save
5
ethereum: 'shiden:https://<IP address or domain>:<PORT>'
Copied!
1
# open docker-compose.yml
2
nano docker-compose.yml
3
4
# modify file and save
5
ethereum: 'shibuya:https://<IP address or domain>:<PORT>'
Copied!
For example, if you are building The Graph node for Shiden, the entire docker-compose.yml now should look like this below:
1
version: '3'
2
services:
3
graph-node:
4
image: graphprotocol/graph-node
5
ports:
6
- '8000:8000'
7
- '8001:8001'
8
- '8020:8020'
9
- '8030:8030'
10
- '8040:8040'
11
depends_on:
12
- ipfs
13
- postgres
14
environment:
15
postgres_host: postgres
16
postgres_user: graph-node
17
postgres_pass: let-me-in
18
postgres_db: graph-node
19
ipfs: 'ipfs:5001'
20
ethereum: 'shiden:http://<IP address or DOMAIN>:<PORT>'
21
RUST_LOG: info
22
ipfs:
23
image: ipfs/go-ipfs:v0.4.23
24
ports:
25
- '5001:5001'
26
volumes:
27
- ./data/ipfs:/data/ipfs
28
postgres:
29
image: postgres
30
ports:
31
- '5432:5432'
32
command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"]
33
environment:
34
POSTGRES_USER: graph-node
35
POSTGRES_PASSWORD: let-me-in
36
POSTGRES_DB: graph-node
37
volumes:
38
- ./data/postgres:/var/lib/postgresql/data
Copied!

Running the Graph containers

Run the following command:
1
sudo docker-compose up
Copied!
When everything is set up you will see the log like this:
Last modified 13d ago