导览 > 将现有子图升级到Graph网络

将现有子图升级到Graph网络

Reading time: 9 min

介绍

链到本节

这是一个关于如何将子图从托管服务升级到Graph的去中心化网络的指南。超过1000个子图已经成功升级到The Graph Network,包括Snapshot、Loopring、Audius、Premia、Livepeer、Uma、Curve、Lido等项目!

升级过程很快,您的子图将永远受益于Graph网络上独有的高可靠性和高性能。

先决条件

链到本节
  • You have a subgraph deployed on the hosted service.

将现有子图升级到Graph网络

链到本节

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.

What next?

链到本节

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密钥

链到本节

你可以在Subgraph Studio这里生成一个API密钥(https://thegraph.com/studio/apikeys/)。

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使用的方式来保护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

重要提示:确保用上一节中生成的实际API密钥替换[api-key]。

现在可以在dapp中使用该查询URL发送GraphQL请求。

恭喜! 你现在是去中心化的先驱了!

注意:由于网络的去中心化特性,不同的索引人可能会索引不同的区块。为了只接收新数据,你可以指定索引人必须索引的最小区块,以便为查询提供区块参数:{ number_gte: $minBlock }字段参数如下例所示:

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

关于网络的性质以及如何处理重组的更多信息将在Distributed Systems(/querying/distributed-systems/) 文档文章中描述。

升级网络上的子图

链到本节

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. 在 The Graph Network 上发布新版本。 请记住,这需要gas(如上一节所述)。

所有者升级费用:Deep Dive

链到本节

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

升级要求GRT从子图的旧版本迁移到新版本。这意味着每次升级都会创建一条新的收益率曲线(这里更多与收益率曲线相关)。

新的收益率曲线对迁移到新版本的所有GRT收取1%的策展税。所有者必须支付其中的50%或1.25%。其余的1.25%由所有策展人承担作为费用。这种激励设计是为了防止子图的所有者能够通过递归升级调用耗尽策展人的所有资金。如果没有策展,您将不得不支付至少100GRT以标记自己的子图。

让我们举个例子,仅当您的子图正在获得积极时才策展会出现这种情况:

  • 在子图的 v1 上使用自动迁移发出 100,000 GRT 信号
  • 所有者升级到 v2。 100,000 GRT 被迁移到新粘合曲线,其中 97,500 GRT 进入新曲线,2,500 GRT 被燃烧
  • 然后,所有者耗费了 1250 GRT 以支付一半的费用。 升级前所有者钱包里必须有这个,否则升级不会成功。 这发生在与升级相同的交易中。

虽然这种机制目前在网络上运行,但社区目前正在讨论降低子图开发人员升级成本的方法。

维护子图的稳定版本

链到本节

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.

子图是外部开发人员正在利用的开放 API。 开放 API 需要遵循严格的标准,以免破坏外部开发人员的应用程序。 在 Graph网络中,子图开发人员必须考虑索引人以及同步新子图、使用子图的其他开发人员需要多长时间。

更新子图的元数据

链到本节

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.

确保选中Update Subgraph Details in Explorer,然后点击保存。 如果选中此项,将生成一个链上交易,更新浏览器中的子图详细信息,而无需发布具有新部署的新版本。

将子图部署到Graph网络的最佳实践

链到本节
  1. 利用 ENS 名称进行子图开发:
  1. 您的个人资料填写得越多,您的子图被索引和管理的机会就越大。

弃用Graph网络上的子图

链到本节

按照这里的步骤废弃您的子图并将其从Graph 网络中删除。

在Graph网络上查询子图 + 计费

链到本节

托管服务的设置允许开发人员不受任何限制地部署他们的子图。

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.

其他资源

链到本节

如果您仍然感到困惑,请不要害怕! 查看以下资源或观看我们的视频指南,了解将子图迁移到下面的去中心化网络:

编辑

上页
在Base上构建子图
下页
AssemblyScript 迁移指南
编辑