Quick start
Last updated
Last updated
Quick start
This tutorial is mainly to guide you through examples and create a subgraph for the contract to demonstrate the process of building the entire environment
First go to https://dashboard.hg.network to add a subgraph. For this subgraph, please select the API deployment, and Huobi Eco Chain.
Enter the subgraph list page, you can see that the newly added subgraph appears in the subgraph list. The prompt given is also different from the subgraphs added in other deployment types. There is a prompt button.
Click the prompt button to display the detailed commands in the deployment and development process
Net, we will start the development of the subgraph according to these commands.
Initialize a new subgraph
To initialize a new subgraph, you need to install the graph-cli development package to use the graph command.
You can use npm or yarn to install globally, the command is as follows:
During the installation process, there may be an error that the libsecret library cannot be found. You can install it separately. For example, on Ubuntu, you can find it through apt search libsecret, and then use the command apt install libsecret-1-dev to install it.
After the installation is complete, we execute graph --help
to get the following content:
There are more detailed instructions behind these commands, and the usage of these commands will also be mentioned in the subsequent process, so I will not expand it here for the time being.
Through these steps, we have installed the command-line environment of graph, and can develop and deploy subgraph.
First, let's create a sample project through graph init to understand
From above, the scaffolding of the project can be created from the sample project
You can also create a project from the contract
<SUBGRAPH_NAME> it is recommended to use the format like "subgraph name/public chain name", which is the name of the subgraph seen on the subgraph details page, such as "subgraphdemo/heco".
<DIRECTORY> is the directory of the project
<CONTRACT_ADDRESS> is the contract address that the subgraph wants to resolve
<NETWORK> is the name of the network where the public chain deployed. For example, the Binance Smart Chain is bsc, and the Huobi Eco Chain is Heco.
Let's demonstrate the usage:
We can successfully create a scaffolding project based on the sample project.
The execution output is shown in the figure below:
Also demonstrate how to create based on the contract:
If it runs successfully, you can get the following output:
As you can see from the above output, specify the contract and network to generate a subgraph project, which will connect to the public chain browser of the corresponding network and retrieve the corresponding contract ABI contract interface definition file.
If you want to deploy this subgraph, please submit this project in the HyperGraph console, which is https://dashboard.hg.network
With this scaffolding project, we can formally develop the subgraph, and analyze the contract matters in the subgraph code. The following chapters will continue to explain