What is the Hosted Service?
Please note, the hosted service will begin sunsetting in 2023, but it will remain available to networks that are not supported on the decentralized network. Developers are encouraged to upgrade their subgraphs to The Graph Network as more networks are supported. Each network will have their hosted service equivalents gradually sunset to ensure developers have enough time to upgrade 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.
First follow the instructions here to install the Graph CLI. Create a subgraph by passing in
graph init --product hosted-service
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.
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.
To build a subgraph tailored for monitoring a Proxy contract, initialize the subgraph by specifying the address of the implementation contract. Once the initialization process is concluded, the last step involves updating the network name in the subgraph.yaml file to the address of the Proxy contract. You can use the command below.
graph init \--product hosted-service--from-contract <IMPLEMENTATION_ADDRESS> \<GITHUB_USER>/<SUBGRAPH_NAME> [<DIRECTORY>]
You can find the list of the supported networks Here.