Hosted Graph Nodes
Introduction
Developers can use Graph Node for subgraph deployment and querying. With this service, they can index data about deployed contracts, logs, and calls. Unfortunately, The Graph's Hosted Service and Subgraph Studio don't contain the Sonic testnet yet, so you have to use the CLI interface to interact with Graph Node.
Creating Subgraph
This article provides more details on creating and using subgraphs on the Sonic testnet. However, please keep in mind that the Sonic testnet still needs to be supported by the Graph CLI, and there are some differences to be aware of.
Install the Graph CLI
The Graph CLI is written in JavaScript, and you will need to install either yarn
or npm
to use it; it is assumed that you have yarn in what follows.
Install with yarn:
Install with npm:
Init Subgraph
At the moment, it's not possible to select the Sonic testnet, so use fantom
as a network. We'll replace it manually later. Fill in your GitHub username (case sensitive) as it will be used later for authentication.
Go into the directory where your subgraph was created, open file networks.json, and rename fantom
to sonic
so it looks like this:
Then open file subgraph.yaml and also replace fantom
with sonic
:
Build Your Subgraph
You can modify any aspect of your subgraph to achieve the desired indexing. More details on how to do that can be found in The Graph documentation.
After you've made all the changes, you can build your subgraph:
Authorization
For deploying your subgraph to the Sonic testnet, you have to obtain a security token, which you'll use for creating, deploying, and removing.
Obtaining this token is similar to how it's done on The Graph's Hosted Service. Go to this login page and log in with your GitHub account. After you log in, you will obtain an access token, which will be used for registering, deploying, and removing actions.
Then you can store your token in the Graph CLI:
Register Your Subgraph
Before you can deploy your subgraph, you have to register its name:
Deploying
Finally, you can deploy your subgraph with this command:
The endpoints to query your subgraph are provided at the end of the deployment log. However, they need to be corrected. Please refer to the next section to learn the correct way to query your subgraph.
Browsing
If everything goes well, your subgraph will be ready, and you can view it in the GraphQL playground at this address:
The endpoint for your application is:
Status of your subgraph is:
Last updated