Cookbook > Upgrading an Existing Subgraph to The Graph Network

Upgrading an Existing Subgraph to The Graph Network

Introduction

Link to this section

This is a guide on how to upgrade your subgraph from the hosted service to The Graph's decentralized network. Over 1,000 subgraphs have successfully upgraded to The Graph Network including projects like Snapshot, Loopring, Audius, Premia, Livepeer, Uma, Curve, Lido, and many more!

The process of upgrading is quick and your subgraphs will forever benefit from the reliability and performance that you can only get on The Graph Network.

Prerequisites

Link to this section
  • You have a subgraph deployed on the hosted service.

Upgrading an Existing Subgraph to The Graph Network

Link to this section

If you are logged in to the hosted service, you can access a simple flow to upgrade your subgraphs from your dashboard, or from an individual subgraph page.

This process typically takes less than five minutes.

  1. Select the subgraph(s) you want to upgrade.
  2. Connect or enter the receiving wallet (the wallet that will become the owner of the subgraph).
  3. Click the "Upgrade" button.

That's it! Your subgraphs will be deployed to Subgraph Studio, and published on The Graph Network. You can access the Subgraph Studio to manage your subgraphs, logging in with the wallet specified during the upgrade process.

You'll be able to view your subgraphs live on the decentralized network via Graph Explorer.

When your subgraph is upgraded, it will automatically be indexed by the upgrade indexer. If the indexed chain is fully supported by The Graph Network, you can add some GRT as "signal", to attract more indexers. It is recommended to curate your subgraph with at least 3,000 GRT to attract 2-3 Indexers for higher quality of service.

You can start to query your subgraph right away on The Graph Network, once you have generated an API key.

Create an API key

Link to this section

You can generate an API key in Subgraph Studio here.

API key creation page

You can use this API key to query subgraphs on The Graph Network. All users start on the Free Plan, which includes 100,000 free queries per month. Developers can sign up for the Growth Plan by connecting a credit or debit card, or by depositing GRT to Subgraph Studio billing system.

Note: see the billing documentation for more information on plans, and on managing your billing on Subgraph Studio.

Securing your API key

Link to this section

It is recommended that you secure the API by limiting its usage in two ways:

  1. Authorized Subgraphs
  2. Authorized Domain

You can secure your API key here.

Subgraph lockdown page

Querying your subgraph on the decentralized network

Link to this section

Now you can check the indexing status of the Indexers on the network in Graph Explorer (example here). The green line at the top indicates that at the time of posting 8 Indexers successfully indexed that subgraph. Also in the Indexer tab you can see which Indexers picked up your subgraph.

Rocket Pool subgraph

As soon as the first Indexer has fully indexed your subgraph you can start to query the subgraph on the decentralized network. In order to retrieve the query URL for your subgraph, you can copy/paste it by clicking on the symbol next to the query URL. You will see something like this:

https://gateway.thegraph.com/api/[api-key]/subgraphs/id/S9ihna8D733WTEShJ1KctSTCvY1VJ7gdVwhUujq4Ejo

Important: Make sure to replace [api-key] with an actual API key generated in the section above.

You can now use that Query URL in your dapp to send your GraphQL requests to.

Congratulations! You are now a pioneer of decentralization!

Note: Due to the distributed nature of the network it might be the case that different Indexers have indexed up to different blocks. In order to only receive fresh data you can specify the minimum block an Indexer has to have indexed in order to serve your query with the block: { number_gte: $minBlock } field argument as shown in the example below:

{
stakers(block: { number_gte: 14486109 }) {
id
}
}

More information about the nature of the network and how to handle re-orgs are described in the documentation article Distributed Systems.

Updating a Subgraph on the Network

Link to this section

If you would like to update an existing subgraph on the network, you can do this by deploying a new version of your subgraph to Subgraph Studio using the Graph CLI.

  1. Make changes to your current subgraph.
  2. Deploy the following and specify the new version in the command (eg. v0.0.1, v0.0.2, etc):
graph deploy --studio --version <version> <SUBGRAPH_SLUG>
  1. Test the new version in Subgraph Studio by querying in the playground
  2. Publish the new version on The Graph Network. Remember that this requires gas (as described in the section above).

Owner Update Fee: Deep Dive

Link to this section

Note: Curation on Arbitrum has a flat bonding curve. Learn more about Arbitrum here.

An update requires GRT to be migrated from the old version of the subgraph to the new version. This means that for every update, a new bonding curve will be created (more on bonding curves here).

The new bonding curve charges the 1% curation tax on all GRT being migrated to the new version. The owner must pay 50% of this or 1.25%. The other 1.25% is absorbed by all the curators as a fee. This incentive design is in place to prevent an owner of a subgraph from being able to drain all their curator's funds with recursive update calls. If there is no curation activity, you will have to pay a minimum of 100 GRT in order to signal your own subgraph.

Let's make an example, this is only the case if your subgraph is being actively curated on:

  • 100,000 GRT is signaled using auto-migrate on v1 of a subgraph
  • Owner updates to v2. 100,000 GRT is migrated to a new bonding curve, where 97,500 GRT get put into the new curve and 2,500 GRT is burned
  • The owner then has 1250 GRT burned to pay for half the fee. The owner must have this in their wallet before the update, otherwise, the update will not succeed. This happens in the same transaction as the update.

While this mechanism is currently live on the network, the community is currently discussing ways to reduce the cost of updates for subgraph developers.

Maintaining a Stable Version of a Subgraph

Link to this section

If you're making a lot of changes to your subgraph, it is not a good idea to continually update it and front the update costs. Maintaining a stable and consistent version of your subgraph is critical, not only from the cost perspective but also so that Indexers can feel confident in their syncing times. Indexers should be flagged when you plan for an update so that Indexer syncing times do not get impacted. Feel free to leverage the #Indexers channel on Discord to let Indexers know when you're versioning your subgraphs.

Subgraphs are open APIs that external developers are leveraging. Open APIs need to follow strict standards so that they do not break external developers' applications. In The Graph Network, a subgraph developer must consider Indexers and how long it takes them to sync a new subgraph as well as other developers who are using their subgraphs.

Updating the Metadata of a Subgraph

Link to this section

You can update the metadata of your subgraphs without having to publish a new version. The metadata includes the subgraph name, image, description, website URL, source code URL, and categories. Developers can do this by updating their subgraph details in Subgraph Studio where you can edit all applicable fields.

Make sure Update Subgraph Details in Explorer is checked and click on Save. If this is checked, an on-chain transaction will be generated that updates subgraph details in the Explorer without having to publish a new version with a new deployment.

Best Practices for Deploying a Subgraph to The Graph Network

Link to this section
  1. Leveraging an ENS name for Subgraph Development:
  • Set up your ENS here
  • Add your ENS name to your settings here.
  1. The more filled out your profiles are, the better the chances for your subgraphs to be indexed and curated.

Deprecating a Subgraph on The Graph Network

Link to this section

Follow the steps here to deprecate your subgraph and remove it from The Graph Network.

Querying a Subgraph + Billing on The Graph Network

Link to this section

The hosted service was set up to allow developers to deploy their subgraphs without any restrictions.

On The Graph Network, query fees have to be paid as a core part of the protocol's incentives. For more information on subscribing to APIs and paying the query fees, check out billing documentation here.

Additional Resources

Link to this section

If you're still confused, fear not! Check out the following resources or watch our video guide on upgrading subgraphs to the decentralized network below:

Edit page

Previous
Building Subgraphs on Base
Next
Quick and Easy Subgraph Debugging Using Forks
Edit page