What is the Hosted Service?
Please note, the Hosted Service will begin sunsetting in Q1 2023, but it will remain available to networks that are not supported on the decentralized network. Developers are encouraged to migrate their subgraphs as more networks are supported. Each network will have their hosted service equivalents gradually sunset to ensure developers have enough time to migrate subgraphs to the decentralized network. Read more about the sunsetting of the Hosted Service here.
This section will walk you through deploying a subgraph to the Hosted Service.
If you don't have an account on the Hosted Service, you can sign up with your GitHub account. Once you authenticate, you can start creating subgraphs through the UI and deploying them from your terminal. The Hosted Service supports a number of networks, such as Polygon, Gnosis Chain, BNB Chain, Optimism, Arbitrum, and more.
For a comprehensive list, see Supported Networks.
Create a Subgraph
First follow the instructions here to install the Graph CLI. Create a subgraph by passing in
graph init --product hosted-service
From an Existing Contract
If you already have a smart contract deployed to your network of choice, bootstrapping a new subgraph from this contract can be a good way to get started on the Hosted Service.
You can use this command to create a subgraph that indexes all events from an existing contract. This will attempt to fetch the contract ABI from Etherscan.
graph init \--product hosted-service--from-contract <CONTRACT_ADDRESS> \<GITHUB_USER>/<SUBGRAPH_NAME> [<DIRECTORY>]
Additionally, you can use the following optional arguments. If the ABI cannot be fetched from Etherscan, it falls back to requesting a local file path. If any optional arguments are missing from the command, it takes you through an interactive form.
--network <ETHEREUM_NETWORK> \--abi <FILE> \
<GITHUB_USER> in this case is your GitHub user or organization name,
<SUBGRAPH_NAME> is the name for your subgraph, and
<DIRECTORY> is the optional name of the directory where
graph init will put the example subgraph manifest. The
<CONTRACT_ADDRESS> is the address of your existing contract.
<ETHEREUM_NETWORK> is the name of the network that the contract lives on.
<FILE> is a local path to a contract ABI file. Both
--abi are optional.
From an Example Subgraph
The second mode
graph init supports is creating a new project from an example subgraph. The following command does this:
graph init --from-example --product hosted-service <GITHUB_USER>/<SUBGRAPH_NAME> [<DIRECTORY>]
The example subgraph is based on the Gravity contract by Dani Grant that manages user avatars and emits
UpdateGravatar events whenever avatars are created or updated. The subgraph handles these events by writing
Gravatar entities to the Graph Node store and ensuring these are updated according to the events. Continue on to the subgraph manifest to better understand which events from your smart contracts to pay attention to, mappings, and more.
Supported Networks on the Hosted Service
You can find the list of the supported networks Here.