Getting started for the Hosted Service
Deploying a Subgraph to the Hosted Service.
After having deployed a subgraph locally, we will focus in the following on deploying a subgraph to The Graph’s Hosted Service. As a prerequisite, you will need an account on The Graph’s Explorer. From here, subgraphs can be created through the UI. The subgraphs created on the explorer can be deployed through your terminal.
Ethereum testnets are supported by The Graph Node aside from The Graph’s mainnet.
The second prerequisite is to add a new subgraph in your dashboard. You can do this by visiting /explorer/dashboard
on The Graph’s Explorer and clicking on Add Subgraph
. Save the new subgraph and you’re ready to go.
Before we start, let’s have a quick look at the steps covered in this guide:
1. Installing Graph CLI.
To install Graph CLI globally on your machine, use the following commands by using Yarn or NPM (depending on which package manager you are using):
2. Setting up an example subgraph.
After installing Graph CLI, you can either set up your own subgraph or use an example subgraph from The Graph:
3. Authenticating with the Hosted Service.
When running the $ graph init
command from above, the CLI will guide you through authenticating with the Hosted Service. It will also help you to prepare and deploy the subgraph. Follow the steps to authenticate and deploy.
If your deployment was successful, your subgraph will start indexing. You can watch your subgraph and interact with it through the GraphQL playground in the Explorer:
4. Using the subgraph in a dApp.
You can now use your own or the example subgraph in a dApp built with React. To do so, open a terminal and select a sample dApp compatible with your subgraph and clone it:
Enter and configure the app directory so that it uses the GraphQL endpoint of your subgraph:
All you need to do now is to install the dependencies of the dApp and start it: