Deploying Subgraph with The Graph

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

What is The Graph?

The Graph is a decentralized protocol for indexing and querying data from blockchains, starting with Ethereum. Fantom Opera now supports this API for making subgraphs and also allows querying the data with graphql through this hosted service. It makes it possible to query data that would be difficult otherwise. 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 delays during intitial indexation of the subgraph, so we recommend liming the indexing interval by specifying a start block value in the subgraph manifest file.

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

Once history indexing is done, performance is not affected.

Creating subgraph in Graph Explorer

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

Adding Subgraph

Go to The Hosted Service page. In the top right corner, there is a button to Sign In with Github. After successful login, you should see My Dashboard.

Go to Dashboard, click on Add Subgraph (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

Once you click on your newly created subgraph, you'll notice the list of commands that you can execute in order to proceed.

  • Install graph command line interface (you can use npm or yarn)

npm install -g @graphprotocol/graph-cli
yarn global add @graphprotocol/graph-cli
  • Initialize the subgraph locally

graph init --product hosted-service <github-username>/<subgraph-name>

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, the name is fantom and for testnet, it is fantom-testnet.

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

graph codegen && graph build

Deploying subgraph to hosted service

To authorize the deployment, you need an access token. You can find it on your Dashboard.

graph auth --product hosted-service <access-token>

To deploy the graph, you can use the following command

graph deploy --product hosted-service <github-username>/<subgraph-name>

And that's it! If everything was successful, you can create graphql requests from GUI in your subgraph accessible from Dashboard. There is also a Logs tab, which will show you the output of the service.

Last updated

© 2024 Fantom Foundation