集成新网络

Graph Node目前可以从以下链类型中索引数据:

如果您对其中任何一种链感兴趣,集成是Graph Node配置和测试的事情。

If you are interested in a different chain type, a new integration with Graph Node must be built. Our recommended approach is developing a new Firehose for the chain in question and then the integration of that Firehose with Graph Node. More info below.

1. EVM JSON-RPC

如果区块链与EVM等效,并且客户端/节点公开标准的EVM JSON-RPC API,Graph Node应该能够索引新的链。有关更多信息,请参阅EVM JSON-RPC测试(new-chain-integration#testing-an-evm-json-rpc)。

  1. Firehose

For non-EVM-based chains, Graph Node must ingest blockchain data via gRPC and known type definitions. This can be done via Firehose, a new technology developed by StreamingFast that provides a highly-scalable indexing blockchain solution using a files-based and streaming-first approach. Reach out to the StreamingFast team if you need help with Firehose development.

EVM JSON-RPC和Firehose之间的区别

链到本节

虽然这两者都适用于子图(Subgraph),但是对于想要构建Substreams 的开发人员,始终需要一个Firehose,比如构建Substreams-powered子图(cookbook/substreams-powered-subgraphs/)。此外,与JSON-RPC相比,Firehose可以实现更快的索引速度。

新的EVM链集成者也可以考虑基于Firehose的方法,考虑到substreams的好处和其大规模并行化的索引能力。支持这两种方法允许开发人员在新链上选择构建substreams或子图。

注意:基于Firehose的EVM链集成仍需要索引器运行链的归档RPC节点,以正确索引子图。这是因为Firehose无法提供通常通过eth_call RPC方法访问的智能合约状态。 (值得提醒的是,eth_calls对于开发人员来说不是一个好的实践(https://thegraph.com/blog/improve-subgraph-performance-reduce-eth-calls/))


测试EVM JSON-RPC

链到本节

为了使Graph Node能够从EVM链中获取数据,RPC节点必须公开以下EVM JSON RPC方法:

  • eth_getLogs
  • eth_call \(对于历史块,使用EIP-1898 - 需要归档节点):
  • eth_getBlockByNumber
  • eth_getBlockByHash
  • net_version
  • eth_getTransactionReceipt, 在JSON-RPC批量请求中
  • trace_filter _(可选择支持Graph Node的调用处理程序)

Graph Node配置

链到本节

首先准备您的本地环境

  1. Clone Graph Node
  2. 修改此行(https://github.com/graphprotocol/graph-node/blob/master/docker/docker-compose.yml#L22),包括新网络名称和符合EVM JSON RPC的URL

    不要更改环境变量名称本身。它必须保持为ethereum,即使网络名称不同也是如此。

  3. 运行IPFS节点,或使用The Graph使用的IPFS节点:https://api.thegraph.com/ipfs/

Test the integration by locally deploying a subgraph

  1. 安装graph-cli
  2. 创建一个简单的示例子图。以下是一些选项:
    1. 预打包的Gravitar智能合约和子图是一个很好的起点
    2. 使用任何现有的智能合约或solidity开发环境使用Hardhat和Graph插件引导本地子图(https://github.com/graphprotocol/hardhat-graph)
  3. 通过将dataSources.network(http://dataSources.network) 更改为之前传递给Graph Node的相同名称,来调整生成的subgraph.yaml。
  4. 在Graph Node中创建子图:graph create $SUBGRAPH_NAME --node $GRAPH_NODE_ENDPOINT
  5. 将子图发布到Graph Node:graph deploy $SUBGRAPH_NAME --ipfs $IPFS_ENDPOINT --node $GRAPH_NODE_ENDPOINT

如果没有错误,Graph Node应该正在同步部署的子图。给它一些时间来同步,然后向API端点发送一些GraphQL查询。


集成一个新的Firehose启用链

链到本节

使用Firehose方法也可以集成新的链。这是目前非EVM链的最佳选择,也是支持substreams的要求。有关如何使用Firehose,为新链添加Firehose支持以及如何将其与Graph Node集成的其他文档。集成者的推荐文档:

  1. Firehose的通用文档(firehose/)
  2. Adding Firehose support for a new chain
  3. 通过Firehose将Graph Node与新链集成(https://github.com/graphprotocol/graph-node/blob/master/docs/implementation/add-chain.md)
编辑

上页
链集成过程概述
下页
Firehose
编辑