Skip to main content

The Graph

Overview: Why is The Graph needed?

note

The Graph team have prepared a highly informative video featuring an overview of the Graph protocol along with some hands-on examples you can try here. This video covers everything you need to know to build support for The Graph into your full stack application, and create subgraphs to query the relevant data.

The Graph is a permissionless and decentralized protocol for indexing and querying data from blockchains. It makes querying fast, reliable, and secure, and allows anyone to build and publish application programming interfaces (APIs) called subgraphs, which act as intermediaries; allowing applications to communicate with one another.

Prerequisites

Before you run a standalone Graph node, you will need:

  • Docker: Containerization platform for software solutions.
  • docker-compose : Used to automate interactions between docker containers.
  • JQ: JSON processor for graph requests.

In this guide, we will walk through setting up an Astar node to gain more insight into transactions on the blockchain by providing indexing data to a standalone Graph node.

Running a Graph Node

After successfully setting up an RPC node, the Graph node needs to be installed and configured to connect from a different container or virtual machine. If you are running a self-signed RPC node, you will need to set up an extra environment variable to allow for this or use a different host.

The first step is to clone the Graph Node repository:

git clone [https://github.com/graphprotocol/graph-node/](https://github.com/graphprotocol/graph-node/) \\
&& cd graph-node/docker

Next, execute the setup.sh file. This will pull all the necessary Docker images and write the necessary information to the docker-compose.yml file. Ensure that docker-compose and jq are installed.

sudo bash ./setup.sh

After running the command, the tail end of the output should be similar to that shown below:



Once everything is set up, you will 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 the RPC's Host IP and writes its value, so you'll need to modify it accordingly.

Modifying the Ethereum Environment

Astar

# open docker-compose.yml
nano docker-compose.yml

# modify file and save
ethereum: 'astar:https://<IP address or domain>:<PORT>'

Shiden

# open docker-compose.yml
nano docker-compose.yml

# modify file and save
ethereum: 'shiden:https://<IP address or domain>:<PORT>'

Shibuya

# open docker-compose.yml
nano docker-compose.yml

# modify file and save
ethereum: 'shibuya:https://<IP address or domain>:<PORT>'

zKyoto

# open docker-compose.yml
nano docker-compose.yml
# modify file and save
ethereum: 'astar-zkevm-sepolia:https://<IP address or domain>:<PORT>'

Astar zkEVM

# open docker-compose.yml
nano docker-compose.yml
# modify file and save
ethereum: 'astar-zkevm:https://<IP address or domain>:<PORT>'

For example, if you are building a Graph node for Shiden, the entire docker-compose.yml now should appear as below:

version: '3'
services:
graph-node:
image: graphprotocol/graph-node
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'shiden:https://<IP address or DOMAIN>:<PORT>'
RUST_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.4.23
ports:
- '5001:5001'
volumes:
- ./data/ipfs:/data/ipfs
postgres:
image: postgres
ports:
- '5432:5432'
command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"]
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
volumes:
- ./data/postgres:/var/lib/postgresql/data

Running The Graph containers

Run the following command:

sudo docker-compose up

When everything is set up the log will appear as below:



For more information and advanced node configuration, consult The Graph official documentation

Define a Subgraph

To start using the Graph node you can now follow the walkthrough to define a Subgraph.