Skip to content

Running a Graph Node on Moonbeam

Introduction

A Graph Node sources events from a blockchain to deterministically update a data store that can be then queried via a GraphQL endpoint.

There are two ways you can set up a Graph Node: you can use Docker to run an all-in-one image, or you can run their Rust implementation. The steps described in this guide will only cover the Docker alternative, as it is more convenient, and you can set up a Graph Node very quickly.

Note

The steps described in this guide have been tested in both Ubuntu 18.04-based and MacOS environments, and they will need to be adapted accordingly for other systems.

The information presented herein is for informational purposes only and has been provided by third parties. Moonbeam does not endorse any project listed and described on the Moonbeam docs website (https://docs.moonbeam.network/).

Checking Prerequisites

Before diving into setting up a Graph Node, you need to have the following installed on your system:

In this guide, you will learn how to run a Graph node against a Moonbase Alpha tracing node with the tracing flag enabled. To spin up a full node with the tracing flag enabled, check out the Debug & Trace guide.

This guide can also be adapted for Moonbeam and Moonriver. To test out the examples in this guide on Moonbeam or Moonriver, you will need to have your own endpoint and API key, which you can get from one of the supported Endpoint Providers.

Running a Graph Node

The first step is to clone the Graph Node repository:

git clone 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 in the docker-compose.yml file.

./setup.sh

The tail end from the logs of the previous command should look something similar to:

Pull complete: d073cd070242 Pull complete: 03790957a916 Pull complete: b3776ac15dab Pull complete: 7144fd00aec4 Pull complete: 54f6491bd120 Pull complete: 247ab23c6036 Pull complete: 57800498c536 Pull complete: beb15a4d14f4 Pull complete: cfc751ecbc6e Pull complete: bbf042afd4a4 Pull complete: 453056a20de6 Pull complete: d5b1a75378ef Pull complete: 78412074775 Digest: sha256:61d5d8ef6c42035f05326b6455c201a809354084c842669048dd35602 Status: Downloaded newer image for postgres: latest Creating docker_postgres_1 ... done Creating docker_ipfs_1 ... done Recreating docker_graph-node_1 ... done Starting graph-node ... done Host IP: 172.18.0.1 Stopping docker_graph-node_1 ... done

Once everything is set up, you need to modify 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.

ethereum: 'moonbeam:http://127.0.0.1:9944'
ethereum: 'moonriver:http://127.0.0.1:9944'
ethereum: 'mbase:http://127.0.0.1:9944'
ethereum: 'mbase:http://127.0.0.1:9944'

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

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: 'mbase:http://127.0.0.1:9944'
      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

Lastly, to run the Graph Node, just run the following command:

docker-compose up
docker-compose up Starting docker_postgres_1 ... done Starting docker_ipfs_1 ... done Recreating docker_graph-node_1 ... done Attaching to docker_ipfs_1, docker_postgres_1, docker_graph-node_1 ipfs_1 | Changing user to ipfs ipfs_1 | IPFS version 0.4.23 ipfs_1 | Initializing IPFS node at /data/ipfs postgres_1 | The files belonging to this database system will be owned by user "postgres" postgres_1 | This user must also own the server process. postgres_1 | The database cluster will be initialized with locale "en_US.utf8" postgres_1 | The default database encoding has accordingly been set to "UTF8" postgres_1 | The default text search configuration will be set to "english" postgres_1 | Data page checksums are disabled. postgres_1 | Fixing permissions on existing directory /var/lib/postgresql/data ... ok postgres_1 | Creating subdirectories ... ok postgres_1 | Selecting dynamic shared memory implementation ... posix postgres_1 | Selecting default max_connections ... 100

After a while, you should see logs related to the Graph Node syncing with the latest available block in the network:

graph-node_1 | Aug 1 11:04:56.017 INFO Starting JSON-RPC admin server at: http://localhost Aug 1 11:04:56.022 INFO Started all subgraphs, component: SubgraphRegistrar graph-node_1 | Aug 1 11:04:56.024 INFO Starting GraphQL HTTP server at: http://localhost:8000, component: GraphQLServer Aug 1 11:04:56.024 INFO Starting index node server at: http://localhost:8030, component: IndexNodeServer Aug 1 11:04:56.028 INFO Starting metrics server at: http://localhost:8040, component: MetricsServer graph-node_1 | Aug 1 11:04:56.029 INFO Starting GraphQL WebSocket server at: ws://localhost:8001, component: SubscriptionServer graph-node_1 | Aug 1 11:04:56.151 INFO Downloading latest blocks from Ethereum. This may take a few minutes..., provider: mbase-rpc-0, component: BlockIngestor graph-node_1 | Aug 1 11:05:03.083 INFO Syncing 1 blocks from Ethereum., code: BlockIngestionStatus, blocks_needed: 1, blocks_behind: 1, latest_block_head: 132365, current_block_head: 132364, provider: mbase-rpc-0, component: BlockIngestor graph-node_1 | Aug 1 11:05:11.715 INFO Syncing 1 blocks from Ethereum., code: BlockIngestionStatus, blocks_needed: 1, blocks_behind: 1, latest_block_head: 132366, current_block_head: 132365, provider: mbase-rpc-0, component: BlockIngestor

And that is it! You have a Graph Node running against the Moonbase Alpha TestNet. Feel free to adapt this example for Moonbeam and Moonriver as well.

The information presented herein has been provided by third parties and is made available solely for general information purposes. Moonbeam does not endorse any project listed and described on the Moonbeam Doc Website (https://docs.moonbeam.network/). Moonbeam Foundation does not warrant the accuracy, completeness or usefulness of this information. Any reliance you place on such information is strictly at your own risk. Moonbeam Foundation disclaims all liability and responsibility arising from any reliance placed on this information by you or by anyone who may be informed of any of its contents. All statements and/or opinions expressed in these materials are solely the responsibility of the person or entity providing those materials and do not necessarily represent the opinion of Moonbeam Foundation. The information should not be construed as professional or financial advice of any kind. Advice from a suitably qualified professional should always be sought in relation to any particular matter or circumstance. The information herein may link to or integrate with other websites operated or content provided by third parties, and such other websites may link to this website. Moonbeam Foundation has no control over any such other websites or their content and will have no liability arising out of or related to such websites or their content. The existence of any such link does not constitute an endorsement of such websites, the content of the websites, or the operators of the websites. These links are being provided to you only as a convenience and you release and hold Moonbeam Foundation harmless from any and all liability arising from your use of this information or the information provided by any third-party website or service.
Last update: August 2, 2024
| Created: April 21, 2021