Build a Graph Node

What is The Graph?

The Graph protocol allows developers to select, index and query data from a blockchain in a way far more flexible than working with supplied standard API links.

The Graph Node continually scans the blockchain for new data "events" to add to an index (also known as a subgraph). Decentralized application (DApp) users benefit from real-time data updates as a result.

What is a Graph Node used for?

A Graph Node scans new blocks looking for data that a developer's particular subgraph may contain. It finds "events" for the subgraph in these blocks, and runs the mapping handlers which the developer provides. The mapping is a WASM module that creates or updates the data events that the Graph Node stores in response to blockchain events.

A DApp queries the Graph Node for data indexed from the blockchain, using the node's GraphQL endpoint. The Graph Node in turn translates the GraphQL queries into queries for its underlying data store in order to fetch this data, making use of the store's indexing capabilities. The DApp displays this data in an information-rich user interface for end users, which they can use to issue new transactions on the blockchain. The cycle repeats.

What you need

HPB does not support The Graph natively yet. To build your own HPB GraphQL API, you need to have following:

Building process for HPB chain (using docker)

  1. Switch to the docker folder and run

  2. Edit docker-compose.yml file by changing the following line:

    ethereum: 'mainnet:http://host.docker.internal:8545'


    ethereum: 'hpb:'

  3. run docker-compose up

Creating a Subgraph

  1. graph create --node http://localhost:8020 [myorganisationname]/[mydappname]

  2. ensure you have a valid subgraph.yaml file, a valid schema.graphql file, and a valid mapping.ts file

  3. Store your smart contract abi in the abis/contract.json (where “contract” is the name of the smart contract) – see example here:

  4. run graph codegen

  5. run yarn add @graphprotocol/graph-ts

  6. run graph deploy [myorganisationname]/[mydappname] --ipfs http://localhost:5001 --node

You should then be able to run queries via http://127.0.01:8000/subgraphs/name/[myorganisationname]/[mydappname]/graphql

Last updated