Comment on page
Deploying Subgraph with The Graph
The process of creating and deploying subgraph with The Graph hosted service
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.
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
Once history indexing is done, performance is not affected.
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.
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 thegraph.com/explorer/<github_name>/<subgraph_name>. Click Create subgraph button. Then you will see it in your Dashboard.
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
fantomand for testnet, it is
- kind: ethereum/contract
- Build the subgraph
graph codegen && graph build
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.