什么是托管服务?
Reading time: 4 min
Please note, hosted service endpoints will no longer be available after June 12th 2024 as all subgraphs will need to upgrade to The Graph Network. Please read more in the
如果您在托管服务上没有账户,您可以用您的 Github 账户注册。一旦进行了身份验证,就可以开始通过 UI 创建子图,并在终端部署它们。托管服务支持许多网络,如 Polygon、 Gnosis Chain、 BNB Chain、 Optimism 和 Arbitrum等。
First follow the instructions to install the Graph CLI. Create a subgraph by passing in graph init --product 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 the block explorer.
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 the block explorer, 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>
是您的 GitHub 用户或组织名称,<SUBGRAPH_NAME>
是您的子图名称,<DIRECTORY>
是Graph init 放置示例子图清单目录的可选名称。<CONTRACT_ADDRESS>
是您现有合约的地址。<ETHEREUM_NETWORK>
是合约所依赖的网络的名称。<FILE>
是合约 ABI 文件的本地路径。网络和 abi 都是可选的。
graph init
支持的第二种模式是从示例子图创建新项目。 以下命令执行此操作:
graph init --from-example --product hosted-service <GITHUB_USER>/<SUBGRAPH_NAME> [<DIRECTORY>]
示例子图基于 Dani Grant 的 Gravity 合约,该合约管理用户头像,并在创建或更新头像时发出 NewGravatar
或 UpdateGravatar
事件。子图通过将 Gravatar
实体写入 Graph 节点存储并确保根据事件更新它们来处理这些事件。继续查看,以便更好地理解智能合约中需要关注的事件、映射等等。
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>]