I have previously developed using theGraph, which is very user-friendly and inexpensive, but I have never understood the internal principles. This time, I will learn together with everyone.
To understand theGraph, one must first grasp a concept called 'indexing.' For those familiar with SQL databases, this is easy to understand; for novices, an analogy can be made:
Looking up a dictionary, you cannot flip through the pages every time you search for a character; instead, you first locate the page by finding the pinyin or radical, then look up the character itself. This significantly improves your efficiency in looking up characters.
The same applies to blockchains; programs need to use specific on-chain data. The blockchain can provide 'How much money does Zhang San have left in total?' data, but cannot directly provide 'How much did Zhang San spend last month?' data.
To know 'How much did Zhang San spend last month in total?', it would be too costly to search through the entire chain from start to finish, so theGraph plays the role of a data 'pinyin' and 'radical', assisting programs in better fetching this aggregated data.
Thus, it can be said that theGraph is primarily a project aimed at developers and on-chain scientists, which ordinary web3 users rarely encounter, but it is omnipresent and extremely important.
TL;DR
theGraph gained strong momentum as a blockchain data provider during the DeFi summer of 2020.
However, the project's overall revenue has been very low due to low fees, while the number of tokens continues to grow, which undoubtedly has a negative effect on token prices.
The project party is now extending its technology to blockchains such as Solana.
Meanwhile, theGraph has competitors such as Bitquery, Covalent, Quicknode, Moralis, etc. Although theGraph has performed well, ongoing low-fee competition has led to very little project revenue.
In the future web3 world, the goal of theGraph is to consolidate all on-chain data into a large collection to provide all users with query services similar to Baidu, Google, and ChatGPT. This goal can be described as very ambitious, but its realization requires time to validate.
Details are as follows:
1. Project's product structure
1. Subgraph: A subgraph needs to be created by developers.
Subgraph includes:
1. The smart contracts to be monitored and their events
2. Events are a convenient interface provided by the Ethereum Virtual Machine (EVM) log infrastructure, equivalent to a ledger recorded on-chain.
3. GraphQL API: Input SQL-like statements for querying, which closely resemble MongoDB SQL statements, in a noSQL-like format.
2. Indexer, operated by indexers.
Including Graph Node nodes and WASM mapping modules.
About WASM: webassembly.org
The specific business process is as follows
1. A dapp adds data to Ethereum through transactions on smart contracts.
2. When processing transactions, smart contracts emit one or more events.
3. The Graph Node continuously scans new Ethereum blocks and the data that may be contained within their subgraphs.
4. The Graph Node finds Ethereum events for the subgraphs written by developers in these blocks and runs the mapping handlers provided by developers. The mapping is a WASM module that creates or updates the data entities stored by the Graph Node in response to Ethereum events.
5. Decentralized applications use the Graph Node's GraphQL API to query data from the Graph Node's indexing of the blockchain. The Graph Node, in turn, transforms GraphQL queries into queries against its underlying data storage to utilize the indexing capabilities of the stored data.
2. Based on the above, it is not difficult to understand that when developers create subgraphs, they need to specify certain content:
Protocol: Select the protocol from which the subgraph will index data.
Subgraph slug: Create a name for the subgraph. The subgraph slug is the identifier for the subgraph.
Directory: Choose the directory in which to create the subgraph.
Ethereum network (optional Layer 2 or mainnet or testnet): It may be necessary to specify which EVM-compatible network the subgraph will index data from.
Smart Contract Address: Find the smart contract address from which to query data.
Smart Contract Name: Enter the name of the smart contract.
ABI: If the ABI is not automatically filled, it needs to be manually input as a JSON file. (Contract code)
Start Block: The starting block should be entered to optimize the subgraph indexing of blockchain data. The starting block can be found by locating the block where the Contract is deployed.
Index contract events as entities: It is recommended to set this to true, as it will automatically add mappings to the subgraph for each event emitted.
Previously, subgraphs only supported EVM networks. With version updates, theGraph has launched substreams, using a Rust-based parallel engine to shorten subgraph indexing times, and it supports ecosystems like Solana while also integrating with traditional databases such as Postgres, Clickhouse, MongoDB, etc.
3. The project has 4 specific roles:
1. Developer: This refers to the individuals who create and maintain subgraphs. Developers can make 100,000 queries per month; for additional queries, they must pay the indexer fees either in $GRT or via bank card. The cost is $2 for every 100,000 queries, and so on.
2. Indexer: Stake $GRT to gain the power to operate as an indexer and receive $GRT rewards. If the data provided by the indexer is incorrect or not timely, they will be penalized. Indexers need to stake at least 100,000 GRT tokens.
3. Delegator: Delegates their $GRT to indexers to maintain the network and earn revenue.
4. Curator: The role of curators is to identify high-quality subgraphs and mark them, encouraging indexers to allocate more resources to operate these subgraphs. Curators can help the network run more effectively.
Curators can share in the income of indexers, but if the quality of the marked subgraphs is poor, the rewards are less.
Curators need to pay $GRT as a deposit to prevent them from being inactive. Curators can only perform their roles after approval from the project party.
4. What is the current status of the project?
theGraph currently supports over 90 networks, including the Ethereum ecosystem, Solana, and others, covering virtually all common chains.
Currently, 10,743 subgraphs have been created, with over 100 Graph Nodes staked by indexers. Delegators earn an APY of 10-20% by delegating their $GRT, and over 75,000 projects use theGraph.
As shown, the protocol's revenue in 2023 was $730,000, and in 2024 it is projected to be $1,240,000. However, the annual expenditure on token incentives reaches tens of millions, far exceeding the protocol's revenue, which means theGraph's earnings for indexers and delegators come from the project's token issuance.
5. The future path of theGraph, referring to its roadmap:
1. In the world of data services, aside from subgraphs, verifiable Firehose serves EIP-4444 and retrieves historical Ethereum data, combined with AI LLMs, and supports multi-chain data interoperability.
2. Developer tools have updated user-friendly UI/UX and migrated to Ethereum Layer 2.
3. Continuously optimize indexer performance using the new Graphix tools.
4. Interconnected data form a new knowledge graph, utilizing AI tools to ultimately achieve a truly decentralized global data knowledge graph.
6. The token economics of theGraph.
The initial token supply is 10 billion GRT, with 3% new tokens issued each year to reward indexers for allocating shares on subgraphs. This means that the total supply of GRT tokens will increase by 3% each year, as new tokens are issued to indexers in recognition of their contributions to the network.
TheGraph has designed various burn mechanisms to offset the issuance of new tokens. Approximately 1% of the GRT supply is burned through various activities on the network each year, and this figure has been increasing with the continued growth of network activity.
These burn activities include: whenever a delegator delegates GRT to an indexer, they need to pay a 0.5% delegation tax; when curators signal on a subgraph, they need to pay a 1% deposit; and 1% of blockchain data query fees.
Currently, the total supply of tokens is 10.79 billion, with the token price around 0.13, and a market cap of approximately 1.2 billion dollars.