关于 Graph

Reading time: 5 min

什么是Graph?

链到本节

The Graph is a powerful decentralized protocol that enables seamless querying and indexing of blockchain data. It simplifies the complex process of querying blockchain data, making dapp development faster and easier.

Understanding the Basics

链到本节

Projects with complex smart contracts such as Uniswap and NFTs initiatives like Bored Ape Yacht Club store data on the Ethereum blockchain, making it very difficult to read anything other than basic data directly from the blockchain.

Challenges Without The Graph

链到本节

In the case of the example listed above, Bored Ape Yacht Club, you can perform basic read operations on the contract. You can read the owner of a certain Ape, read the content URI of an Ape based on their ID, or read the total supply.

Why is this a problem?

链到本节

It would take hours or even days for a decentralized application (dapp) running in a browser to get an answer to these simple questions.

Alternatively, you have the option to set up your own server, process the transactions, store them in a database, and create an API endpoint to query the data. However, this option is resource intensive, needs maintenance, presents a single point of failure, and breaks important security properties required for decentralization.

Blockchain properties, such as finality, chain reorganizations, and uncled blocks, add complexity to the process, making it time-consuming and conceptually challenging to retrieve accurate query results from blockchain data.

The Graph Provides a Solution

链到本节

The Graph solves this challenge with a decentralized protocol that indexes and enables the efficient and high-performance querying of blockchain data. These APIs (indexed "subgraphs") can then be queried with a standard GraphQL API.

Today, there is a decentralized protocol that is backed by the open source implementation of Graph Node that enables this process.

How The Graph Functions

链到本节

Indexing blockchain data is very difficult, but The Graph makes it easy. The Graph learns how to index Ethereum data by using subgraphs. Subgraphs are custom APIs built on blockchain data that extract data from a blockchain, processes it, and stores it so that it can be seamlessly queried via GraphQL.

Specifics

链到本节
  • The Graph uses subgraph descriptions, which are known as the subgraph manifest inside the subgraph.

  • The subgraph description outlines the smart contracts of interest for a subgraph, the events within those contracts to focus on, and how to map event data to the data that The Graph will store in its database.

  • When creating a subgraph, you need to write a subgraph manifest.

  • After writing the subgraph manifest, you can use the Graph CLI to store the definition in IPFS and instruct an Indexer to start indexing data for that subgraph.

The diagram below provides more detailed information about the flow of data after a subgraph manifest has been deployed with Ethereum transactions.

一图解释Graph如何使用Graph节点向数据消费者提供查询的图形

流程遵循这些步骤:

  1. 一个去中心化的应用程序通过智能合约上的交易向以太坊添加数据。
  2. 智能合约在处理交易时,会发出一个或多个事件。
  3. Graph 节点不断扫描以太坊的新区块和它们可能包含的子图的数据。
  4. Graph 节点在这些区块中为你的子图找到以太坊事件并运行你提供的映射处理程序。 映射是一个 WASM 模块,它创建或更新 Graph 节点存储的数据实体,以响应以太坊事件。
  5. 去中心化的应用程序使用Graph节点的GraphQL 端点,从区块链的索引中查询 Graph 节点的数据。 Graph 节点反过来将 GraphQL 查询转化为对其底层数据存储的查询,以便利用存储的索引功能来获取这些数据。 去中心化的应用程序在一个丰富的用户界面中为终端用户显示这些数据,他们用这些数据在以太坊上发行新的交易。 就这样周而复始。

下一步

链到本节

The following sections provide a more in-depth look at subgraphs, their deployment and data querying.

Before you write your own subgraph, it's recommended to explore Graph Explorer and review some of the already deployed subgraphs. Each subgraph's page includes a GraphQL playground, allowing you to query its data.

编辑

上页
开始
下页
支持的网络
编辑