# Running a Graph Node on REI Network

### Introduction <a href="#introduction" id="introduction"></a>

The Graph is a decentralized protocol for indexing and querying data from blockchains, starting with Ethereum. It makes it possible to query data that is difficult to query directly. Graph nodes which source events from blockchain to deterministically update a data store that can be queried via the GraphQL endpoint

There are two ways to  launch a Graph Node: you can use Docker to run related images, or you can compile their [Source code](https://github.com/graphprotocol/graph-node). The steps described in this document will only be run through docker, because it is more convenient, and you can launch a Graph Node very quickly.

{% hint style="info" %}
The steps described in this guide have been tested in both Ubuntu 20.04-based and MacOs environments, and they will need to be adapted accordingly for other systems.
{% endhint %}

### Prerequisites <a href="#checking-prerequisites" id="checking-prerequisites"></a>

Before you start, you need some pre-environment configuration on your system:

* [Docker](https://docs.docker.com/get-docker/)
* [Docker Compose](https://docs.docker.com/compose/install/)

In this guide, you will learn how to run a Graph node against a node with the REI testnet node.This guide can also be adapted for mainnet.

### Running a Graph Node <a href="#running-a-graph-node" id="running-a-graph-node"></a>

The first step is to clone the [Graph Node repository](https://github.com/graphprotocol/graph-node/):

```atom
git clone https://github.com/graphprotocol/graph-node/
cd graph-node/docker
```

Then execute the `setup.sh` file, this file will pull all the necessary Docker images and write the necessary information into the `docker-compose.yml` file.

```
./setup.sh
```

The log information returned looks like:

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FjvnKqjikQlXkN2c5D1wy%2FdokerPull.png?alt=media\&token=0d43aa61-83bc-411e-aa47-8f35ae4693a4)

When everything is ready, you should to revise the "Ethereum environment" inside the `docker-compose.yml` file, so that it points to the endpoint of the node you are running this Graph Node against. Note that the `setup.sh` file detects the `Host IP` and writes its value, so you'll need to modify it accordingly.

The entire `docker-compose.yml` file should look something similar to:

```docker
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: 'reitest:http://127.0.0.1:3030'
      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
```

Finally, you can start with the following command：

```
docker-compose up
```

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FZYqHRP1Y1EVvowzoqkFl%2FdockerUp.png?alt=media\&token=d9e33a77-bfa0-4ea8-8f68-8b5e4b62814b)

Wait for a while and you will see the log with the latest block synced：

![](https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FMWAITMRHsjxd3WjZ13od%2FnodeUp.png?alt=media\&token=cccd27a7-cc06-4807-985c-8d44870ff648)

As you can see, you have a Graph Node running against the REI TestNet. This example is also suitable for mainnet

### References

{% embed url="<https://thegraph.com/docs/en/developer/quick-start>" %}
