How to Integrate The Graph and Create and Deploy a Subgraph Using MegaNode Archive Node
In this tutorial, we will be using NodeReal’s Meganode Archive Node RPC endpoints to integrate TheGraph with our archive node and index the data to fetch data as per our requirements.
In this tutorial, we will be using NodeReal’s MegaNode Archive Node RPC endpoints to integrate TheGraph 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.
Pre-requisites:
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.
Tools Required:
- 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: https://github.com/pranavdaa/Graph-Node-Local
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:
https://github.com/RumeelHussainbnb/BAS-Nodereal-Demo-TheGraph
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.
Join Our Community
Join our community to learn more about NodeReal and stay up to date with us!