Quick start

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

  1. 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.

  1. 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:

# NPM
npm install -g @hgdotnetwork/graph-cli
# Yarn
yarn global add @hgdotnetwork/graph-cli

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

graph init [options] [subgraph-name] [directory]
Options:
 --allow-simple-name Use a subgraph name without a prefix (default: false)
 -h, --help Show usage information
Choose mode with one of:
 --from-contract <address> Creates a scaffold based on an existing contract
 --from-example Creates a scaffold based on an example subgraph
Options for --from-contract:
 --abi <path> Path to the contract ABI (default: download from Etherscan)
 --network <mainnet|kovan|rinkeby|ropsten|goerli|poa-core|poa-sokol|xdai|matic|mumbai|fantom|bsc|heco|clover>
 Selects the network the contract is deployed to
 --index-events Index contract events as entities
 --contract-name Name of the contract (default: Contract)

From above, the scaffolding of the project can be created from the sample project

graph init --from-example <SUBGRAPH_NAME> [<DIRECTORY>]

You can also create a project from the contract

graph init --from-contract <CONTRACT_ADDRESS> <SUBGRAPH_NAME> --network <NETWORK> [<DIRECTORY>]

<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:

graph init --from-example subgraphdemo/heco --network heco

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:

graph init subgraphdemo/heco --network heco --from-contract 0x0bb480582ecae1d22bbaeaccfbb849b441450026

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

Last updated