The Graph 1 Overview

This article is reproduced from the official document

What is The Graph

The Graph is a decentralized protocol for indexing and querying blockchain data, first started with Ethereum. It makes it possible to query data that is difficult to query directly.

Projects with complex smart contracts like Uniswap, and NFTs initiatives like Bored Ape Yacht Club store data on the Ethereum blockchain, so in addition to reading basic data directly from the blockchain, I would like to implement some Other queries are really hard.

In the case of Bored Ape Yacht Club, we can do basic read operations on the contract, such as getting the owner of a certain Ape, getting the content URI of a certain Ape based on their ID, or the total supply, because these read Operations are programmed directly into smart contracts, but more advanced queries and operations such as aggregations, searches, relations, and non-coarse filtering are not possible. For example, if we wanted to query the apes owned by an address and filter by some characteristic of it, we wouldn't be able to get that information by interacting directly with the contract itself.

In order to get this data, you have to process every event ever sent , read metadata from IPFS using Token ID and IPFS hash value, and then aggregate it. Even these types of relatively simple queries can take hours or even days for a decentralized application (dapp) running in a browser to get an answer.

You can also set up your own server, process the transactions there, save them to the database, and set up an API terminal on it to query the data. However, this option is resource intensive, requires maintenance, presents a single point of failure, and undermines important security properties needed for decentralization.

Indexing blockchain data is really, really hard.

Properties of blockchains, such as finality, chain reorganizations, or unsealed blocks, further complicate this process and make retrieving correct query results from blockchain data not only time-consuming, but also conceptually difficult. difficult.

The Graph solves this problem with a decentralized protocol that indexes blockchain data and enables high-performance and efficient queries. These APIs ("subgraphs" of the index) can then be queried with standard GraphQL APIs. Today, there is an escrow service and there is a distributed decentralized protocol that does the same. Both are supported by the open source implementation of Graph Node.

How The Graph Works

The Graph learns what to index and how to index Ethereum data based on the description of the subGraph (called the subgraph manifest). The subgraph manifest defines the smart contracts that subGraph is concerned with, the events that need to be concerned about in these contracts, and how to map event data to the data that The Graph will store in its database.

Once you've written your subgraph manifest, you can use Graph CLI to store that definition in IPFS and tell indexers to start indexing data for that subgraph.

The following figure shows more details of processing the Ethereum transaction data flow after deploying the subgraph manifest .

The process follows these steps:

  1. A decentralized application adds data to Ethereum through transactions on smart contracts.

  1. When a smart contract processes a transaction, it emits one or more events.

  1. Graph nodes are constantly scanning Ethereum for new blocks and the subGraph data they may contain.

  1. Graph nodes find Ethereum events for your subgraph in these blocks and run the map handler you provide. Mapping is a WASM module that creates or updates data entities stored by Graph Nodes in response to Ethereum events.

  1. 去中心化的应用程序使用节点的GraphQL 端点,从区块链的索引中查询 Graph 节点的数据。 Graph 节点反过来将 GraphQL 查询转化为对其底层数据存储的查询,以便利用存储的索引功能来获取这些数据。 去中心化的应用程序在一个丰富的用户界面中为终端用户显示这些数据,他们用这些数据在以太坊上发行新的交易。 就这样周而复始。

在下面的章节中,我们将更详细地介绍如何定义子图,如何部署它们,以及如何从 Graph 节点建立的索引中查询数据。

Guess you like

Origin blog.csdn.net/gambool/article/details/128672438