Table of Contents
The Graph is a decentralized protocol for indexing and querying blockchain data that makes it possible to query data that is difficult to query directly.
Projects with complex smart contracts such as Uniswap and NFT projects like Bored Ape Yacht Club store data on the Ethereum blockchain, making it difficult to read anything but the most basic information.
In the case of Bored Ape Yacht Club, it’s possible to perform basic read operations on the contract such as getting the owner of a certain Ape, getting the content URI of an Ape based on their ID, or the total supply, as these read operations are programmed directly into the smart contract. More advanced real-world queries and operations like aggregation, search, relationships, and non-trivial filtering however are not possible. For example, if we would like to query all Apes owned by a certain address and filter results by one of its characteristics, we cannot rely on the contract itself as it cannot provide historical information.
If we wanted to obtain this kind of data ourselves, then we would need to process every transfer event ever emitted from the BAYC smart contract, read the metadata from IPFS using the Token ID and IPFS hash, and then aggregate all the results. Put simply, to answer these kinds of relatively simple questions, it would take hours or even days for a decentralized application running in a browser to obtain a result.
A better solution would be to use a server to process the transactions and save them to a database, and an API endpoint could be configured on top to query the data. However, this would open up a whole new can of worms, which is why The Graph exists.
GraphQL
The Graph makes use of a structured query language called GraphQL, developed and then later open-sourced by Facebook. GraphQL provides a flexible and more efficient alternative to the traditional REST API, allowing for the structuring of highly precise queries that return only the data developers need, via a single endpoint.
The Graph is decentralized and is powered by hundreds of independent Indexers running Graph Node, serving data queries to developers across the web3 ecosystem. Indexers identify blockchain data based on information provided by subgraphs.
Subgraphs
Subgraphs are open APIs that can be created or queried by anyone. It’s essentially a definition created by a developer that specifies which data The Graph should index from the blockchain, and how it should be stored. Once a subgraph is published to The Graph Network, it can be easily queried using an API key.
To define a subgraph, developers write a manifest and a set of GraphQL schemas. This instructs Indexers on The Graph which events to listen for on the blockchain, and how to map event data to entities that can be queried using GraphQL. Since developers can define their own subgraphs, they have considerable flexibility in the way they index and expose blockchain data to their applications. Alternatively, since The Graph is permissionless and open-source, dapp developers can also query pre-existing subgraphs already available on The Graph Network if they find a subgraph that meets their data needs.
Running a Graph Node to index data on Astar Network
Astar Network may be unique in the sense that it spans across a variety of smart contract platforms in both the Ethereum as well as Polkadot ecosystems. This makes running a Graph Node for Astar a little more complex than doing so on smaller networks, as three production networks (zkEVM, Wasm, and EVM), and their testnet + canary counterparts all need to be indexed to capture metrics and events end-to-end, which also requires substantially more compute and storage resources. There are other nuances to running Astar nodes as well. For example, RPC nodes on the Polkadot side will default to the Wasm vs. EVM smart contract chain, so an additional flag needs to be specified to begin indexing EVM transactions and events if that is unexpected.
To learn more about supporting Astar network infrastructure and challenges at scale, consult our official documentation. If you would like to jump right in and start running a Graph Node to index blockchain data on Astar, check out this walkthrough.
In Summary
As the decentralized data layer for web3, The Graph represents a pivotal innovation for accessing blockchain data and building decentralized applications. By leveraging GraphQL for efficient and precise data querying, it addresses a critical gap in the blockchain ecosystem — providing dapp developers with the ability to easily access complex data from smart contracts and blockchain events. The Graph offers developers the flexibility and power to create tailored subgraphs that are low cost, performant, and permissionless. This not only simplifies data retrieval from the blockchain but also opens up new possibilities for the development of sophisticated and data-rich decentralized applications. As blockchain technology continues to evolve and integrate into various sectors, The Graph stands out as an essential tool for developers looking to harness the full potential of blockchain data.
About The Graph
The Graph is the source of data and information for the decentralized internet. As the original decentralized data marketplace that introduced and standardized subgraphs, The Graph has become web3’s method of indexing and accessing blockchain data. Since its launch in 2018, tens of thousands of developers have built subgraphs for dapps across 40+ blockchains - including Ethereum, Arbitrum, Optimism, Base, Polygon, Celo, Fantom, Gnosis, and Avalanche.
As demand for data in web3 continues to grow, The Graph enters a New Era with a more expansive vision including new data services and query languages, ensuring the decentralized protocol can serve any use case - now and into the future!
Discover more about how The Graph is shaping the future of decentralized physical infrastructure networks (DePIN) and stay connected with the community.
Follow The Graph on X, LinkedIn, Instagram, Facebook, Reddit, and Medium! Join the community on The Graph’s Telegram, join technical discussions on The Graph’s Discord.
About Astar Network
Astar Network is the gateway for projects across enterprises, entertainment & gaming in Japan and beyond, driving global adoption and delivering web3 to billions. It leverages a cross-virtual machine powered by Polygon and Polkadot to offer customizable blockchain solutions that accelerate web3 adoption. With zk-powered Ethereum L2 Scaling (zkEVM), EVM, Wasm, and a cutting-edge ecosystem, Astar delivers robust, secure, and interoperable web3 technology. Astar zkEVM is the new Layer-2 solution to scale a web3 experience on Ethereum with zero knowledge (ZK) technology. Astar Network adds an EVM equivalent environment that is seamlessly compatible with existing smart contracts, developer tools, and wallets on Ethereum.