Cookbook > Upgrading an Existing Subgraph to The Graph Network

Upgrading an Existing Subgraph to The Graph Network

Reading time: 7 min

Введение

Ссылка на этот раздел

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.

Предварительные требования

Ссылка на этот раздел
  • You have a subgraph deployed on the hosted service.

Upgrading an Existing Subgraph to The Graph Network

Ссылка на этот раздел

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.

Создание API ключа

Ссылка на этот раздел

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.

Обеспечение безопасности вашего API ключа

Ссылка на этот раздел

Рекомендуется обеспечить безопасность доступа к API, ограничивая его использование двумя способами:

  1. Авторизованные подграфы
  2. Авторизованный домен

You can secure your API key here.

Subgraph lockdown page

Запрос вашего подграфа в децентрализованной сети

Ссылка на этот раздел

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 7 Indexers successfully indexed that subgraph. Also in the Indexer tab you can see which Indexers picked up your subgraph.

Rocket Pool subgraph

Как только первый индексатор полностью проиндексирует ваш подграф, вы можете начать делать запросы к нему в децентрализованной сети. Чтобы получить URL запроса для вашего подграфа, вы можете скопировать/вставить его, нажав на символ рядом с URL запроса. Вы увидите что-то вроде этого:

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.

Теперь вы можете использовать этот URL-адрес запроса в своем приложении для отправки своих запросов GraphQL.

Поздравляю! Теперь вы являетесь пионером децентрализации!

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

Ссылка на этот раздел

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. Задеплойте следующее и укажите новую версию в команде (например, v0.0.1, v0.0.2 и т. д.):
graph deploy --studio --version <version> <SUBGRAPH_SLUG>
  1. Test the new version in Subgraph Studio by querying in the playground
  2. Опубликуйте новую версию в сети Graph. Помните, что для этого требуется газ (как описано в разделе выше).

Owner Update Fee: Deep Dive

Ссылка на этот раздел

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.

Давайте приведем пример, это только в том случае, если ваш сабграф активно курируется на:

  • 100 000 GRT сигнализируемая с помощью автоматической миграции на v1 подграфа
  • 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.

Поддержание стабильной версии подграфа

Ссылка на этот раздел

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.

Обновление метаданных подграфа

Ссылка на этот раздел

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.

Рекомендации по развертыванию подграфа в сети Graph

Ссылка на этот раздел
  1. Использование имени ENS для разработки подграфа:
  • Set up your ENS here
  • Add your ENS name to your settings here.
  1. Чем более заполнены ваши профили, тем больше шансов, что ваши подграфы будут проиндексированы и обработаны куратором.

Удаление подграфа в сети Graph

Ссылка на этот раздел

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

Запрос подграфа + выставление счетов в сети Graph

Ссылка на этот раздел

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.

Дополнительные источники

Ссылка на этот раздел

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:

Редактировать страницу

Предыдущий
How to Secure API Keys Using Next.js Server Components
Следующий
Создание субграфов на Base
Редактировать страницу