Table of Content

How to Integrate The Graph and Create and Deploy a Subgraph Using MegaNode Archive Node

Lesson Objectives

By the end of this lesson, you will be able to:

  • Integrate the Graph with use NodeReal's MegaNode Archive Node RPC endpoints
  • Index historical blockchain data and fetch it as per your requirements.
  • Deploy Subgraphs.


In this lesson, we will be using NodeReal’s MegaNode Archive Node RPC endpoints to integrate The Graph with our archive node and index the data to fetch data as per our requirements.

Here is a quick guide on The Graph EVM Chain integration.

What is The Graph

The Graph is an indexing protocol for organizing blockchain data and making it easily accessible with GraphQL.

What is Nodereal's Meganode

The archive node has all the historical data of the blockchain. In some cases, if you need to access the data from earlier blocks, you will need to access the archive node. It requires huge storage to run an archive node, and typically due to this huge amount of data, it takes a longer time to process.

MegaNode provides industry-leading capabilities for archive node on BSC. It is the fastest and always consistent. MegaNode provides archive data and debugs API on archive node.


For this lesson, it is necessary that you have an application up and running on the MegaNode Archive Node. For more information on how to get an application running on MegaNode Archive Node, please refer here. Currently, NodeReal provides a 3-month FREE trial version for accessing MegNode PRC/Archive Node. Other than this, following are the software requirements.

Software Pre-requisites

  • Docker
  • Git
  • Node.js
  • NPM
  • Yarn

Before we start, you will need to log in MegaNode Service first and find your API keys. Here is a quick guide.


Steps to Run The Graph Node Locally

Step1: Clone the following repo using the command gh repo clone pranavdaa/Graph-Node-Local

Graph Node Local Repo:



Step 2: Go into The Graph-Node-Local directory to access the files.


Step 3: Edit the docker-compose.yml file to incorporate your network details. Mention your network name in the docker-compose.yml file as well as add the RPC, the API key just mentioned, as shown in the figure below.


Step 4: Issue the command docker-compose up to get The Graph node running within a docker container.


Step5: You can also view the running container in Docker Desktop application.


Creating and Deploying Subgraph

For this tutorial, we will be using the WrappedBNB contract for indexing. You can get the address and contact name of the WBNB contract from BSCScan. Issue The Graph init command to initialize a scaffold project. This command runs you through a wizard that asks the user to specify different details for the project as shown in the figure below.

Remember, in this example, we have used the contract address and name of WBNB as mentioned above.


This will create a sub-directory within your current directory where the command was issued with the name specified by the user, WBNB in our case. Move into this directory.


Within this directory, edit the subgraph.yaml file to specify the network name and the starting block number from where you want to start indexing the data, as shown in the figure below.


We also edit the schema.graphql file to define our schema i.e. data model. The GraphQL schema defines what data you wish to retrieve from the subgraph.


Issue the npn run codegen command that will generate all mappings, types, migrations, etc for you.


The schema.ts is one of the files generated by running the codegen command. This contains the entities and the functions for fetching and setting data values.


Similarly, the mapping.ts file provides handlers for the different entities defined, as shown below. Here we defined the functionality for the handleDeposit function. You can define it as per your need.


To create a subgraph on the local graph node issue the command npm run create-local


Deploy your subgraph on the local graph node using the command npm run deploy-local


To query the subgraph, refer to the query endpoints generated after successfully deploying the subgraph, as shown in the figure above.

To query your subgraph follow the link given after successful deployment of subgraph, http://localhost:8000/subgraphs/name/bas/wbnb/graphql in our case.


Source Code Github URL:

You can find the complete source code for this project here.

MegaNode Archive Node Performance

The reason why you should consider choosing to use Nodereal’s MegaNode archive node service is the pre-eminent response time it offers. After indexing our data using The Graph’s subgraph service, the average response for querying the data is currently the FASTEST time available in the market with a 100% success rate.


Again, if you are looking for archive node services, getting started with MegaNode will be your wisest decision. Sign up here for a 3-month FREE trial of Growth Plan.


In this lesson, we provided our readers a demonstration on how to use NodeReal's MegaNode Archive Node RPC endpoints by integrating The Graph with our archive node and index the data to fetch data as per our requirements.

Table of Content