Deploying subgraph with The Graph

The process of creating and deploying subgraph with The Graph hosted service

What The Graph is

The Graph is a decentralized protocol for indexing and querying data from blockchains, starting with Ethereum. Fantom Opera now supports this API of making subgraphs and query data with graphql thru this hosted service. It makes it possible to query data that is difficult to query directly. More information can be found here.

Supported features

Fantom Opera chain now also supports Call Handlers, so they can be used in any subgraph deployed to hosted service. You can experience longer times during intitial indexation of the subgraph, so we recomend to limit indexing interval with start block in subgraph manifest file.

- kind: ethereum/contract
name: ExampleSource
network: fantom
address: '0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95'
abi: ExampleContract
startBlock: 3037823

Once history indexing is done, performace is not affected.

Creating subgraph in Graph explorer

Purpose of this tutorial is not to describe, how to create mappings between smart contracts and final graphql requests, but how to use hosted service to deploy created subgraph and make it accessible to the world. If you want to start from scratch, please use this documentation to define a new subgraph.

Creating account

Go to The Graph Explorer page. In the top right corner, there is a button to Sign In with Github. After successful login, you will see your Github account profile picture. Click it and selecet Dashboard.

Adding Subgraph

In your Dashboard, click Add Subgraph button on the right side. Fill in the specified mandatory fields, which are subgraph name and subtitle. Select your github account. When you will be filling subgraph name, you can see the URL which will be used for it in future, something like<github_name>/<subgraph_name>. Click Create subgraph button. Then you will see it in your Dashboard.

Setting Fantom as a target network

In your subgraph project, there is a manifest file in the root folder, called subgraph.yaml or similar name according to configuration. Inside you have to specify network name as a target. For Fantom Opera chain is the name fantom.

# ...
- kind: ethereum/contract
name: Gravity
network: fantom
address: '0x50DD37ac4fC2D7FbaafC07131D9Fe9788dc9df90'
abi: Gravity
kind: ethereum/events

Deploying subgraph to hosted service

Use Yarn or NPM to install graph command line interface

yarn global add @graphprotocol/graph-cli

Then you need your access token, to be able to authorize. You can find it in your Dashboard on the explorer page. Then for deploy it self use this command.

graph deploy --access-token '<access_token>' --node --ipfs <github_name/subgraph_name> subgraph.yaml

And that's all. If everything was successful, then you can try your graphql requests from GUI in your subgraph details page accessible from Dashboard. There is also a tab called Logs, so you can see output of the service.