Bringing Indexed Data from The Graph to Smart Contracts with Chainlink Oracles
is excited to announce an integration with , the market-leading decentralized oracle network. The integration will allow indexed data from The Graph’s APIs, called subgraphs, to be relayed to smart contracts via Chainlink oracles. This opens up opportunities for developers to use indexed data sets to build powerful, truly decentralized applications.
Below are three use cases where developers can use Chainlink oracles to access subgraphs on-chain to augment the value of their decentralized application:
- Using a subgraph to catalog on-chain liquidity to calculate and compare slippage of potential trades made on a DEX and other DeFi applications
- Using a subgraph to catalog the average gas consumed per block for each transaction to calculate recommended gas fees
- Using subgraphs as APIs for integrating global, real-world (off-chain) data into dApps such as gaming results, user identities, off-chain financial assets and more
is an example of a DeFi dApp that combines the best of middleware protocols: using and powering their exchange UI using a . This integration is the start of an expansion in middleware protocols that seamlessly integrate, providing the necessary infrastructure to build truly serverless and decentralized applications.
The Graph: Building Open APIs for Web3
Indexing is a way of structuring and categorizing data so it can be easily searched for and queried by users. Google is a famous example of indexing web data, substantially decreasing the time it takes for users to find and use information on the Internet. Without data indexing, users would need to manually scroll through unorganized data stores filled with raw and unmapped data to find the information they need.
Blockchains are increasingly becoming data-rich environments, both through data generation activities on-chain (smart contract events and calls) and through dApps bringing external data on-chain via oracles. All dApps that show blockchain data in their UIs require indexed data to reference the information they need and create good user experiences.
Before The Graph, developers had to write their own indexing code and maintain servers and databases on centralized infrastructure. This introduces a central point of failure; the indexed data can be maliciously or mistakenly manipulated by the dApp or the single server can go offline. Furthermore, developers have to spend extra time and money to run the infrastructure themselves. Deploying a subgraph is the most efficient way for developers to index blockchain data.
The Graph solves the problem of centralized data indexing by building a decentralized protocol for indexing blockchain data. Today subgraphs can be deployed to The Graph’s hosted service and a decentralized network will be launching later this year. This will ensure that data remains open and that dApps continue to run no matter what.
With the decentralized network, users will no longer have to trust teams to operate servers and developers can deploy to reliable public infrastructure they don’t have to manage. The Graph uses GraphQL, an open-source query language widely used by the web developer community. It provides a powerful API to get exactly the data users need in a single request, seamlessly traversing and combining data sources. GraphQL makes it easy for Web2 developers to build in Web3.
Chainlink: Bridging Indexed Data with Smart Contracts
Blockchain activity alone produces several valuable on-chain data sets that are increasingly attractive for use in decentralized applications. While the raw data may not be as useful for a dApp, the indexed and compiled data can be. Most data presented in a dApp UI (eg. user balances, digital art, votes) is blockchain data indexed by The Graph. Useful indexed data includes gas data to determine the recommended gas fee, block times to determine the average block time, a DEX’s on-chain liquidity to calculate slippage, and much more.
Broadcasting off-chain data and storing it on-chain is another important area where data indexing becomes useful. For example, deploying a subgraph that includes the schema and manifest for consuming blockchain data can be useful for analyzing historical data, such as determining the quality of an oracle node based on past response time to a price data query, the accuracy of those responses, the number of jobs completed, and more.
The next important feature is making data indexed by The Graph available to smart contracts via secure and reliable oracles. Chainlink is a framework for building decentralized oracle networks that is critical to data sharing between decentralized applications. It allows users to decentralize both the node operator and data source of an oracle network, as well as incorporate advanced features such as trusted execution environments and . Being the across an increasing number of different blockchains, Chainlink oracles make for a natural combination with The Graph for dApps across blockchain environments to index data and deliver that data to smart contracts.
All subgraphs are potential data sources for Chainlink oracles that can feed into a smart contract to trigger execution or feed into off-chain computation protocols. Access to subgraphs enables more data-rich oracles. Smart contracts can also use Chainlink oracles to trigger the indexing of data on The Graph.
As part of the integration, The Graph will index DEX liquidity data that Chainlink oracles can bridge to DEX UIs as reference data for calculating slippage based on a user’s trade size. The Graph will also create an index that catalogs gas prices paid per transaction. dApps can reference this Gas Station API via Chainlink to calculate the recommended gas price. Finally, there are plans to develop a universal API to allow smart contracts access to any subgraph using a Chainlink decentralized oracle network. Thus, developers can index real-world data and use it in their smart contracts, such as gaming results, user profiles, and more.
Some initial work on integrating Chainlink and The Graph was also done by a team at ETHBerlin Zwei hackathon. allows smart contracts to run queries on The Graph and have the results posted back to the smart contracts.
Seeding Middleware Infrastructure for Accelerated Smart Contract Development
We have already seen the creation of several stand-alone applications that either function completely on-chain, or use oracles to enhance their ability to produce value for users. In our opinion, smart contract technology has only scratched the surface of its potential due to a lack of decentralized middleware infrastructure. This is rapidly changing, as the tools available to developers outside of the base layer are growing, including The Graph for indexing and querying data, Chainlink for oracles, Ceramic for storing data, LivePeer for video streaming, Unstoppable Domains for web hosting, and many more. Together, these middleware protocols will make developing a smart contract substantially easier, while providing access to more functionality.
“We’re thrilled to collaborate with Chainlink to bring a vast amount of new blockchain datasets to developers, augmenting the value of their decentralized applications. Through The Graph, developers can start cataloging important blockchain data, such as gas prices and slippage, and securely relay them to their dApps using Chainlink oracles. This brings end-to-end decentralization of data indexing and data retrieval, a critical step in abstracting complexity to allow for more advanced dApp development.”
About Chainlink
If you’re a developer and want to connect your smart contract to existing data and infrastructure outside the underlying blockchain, reach out to them . They can help you quickly and securely launch your data-enabled application or on mainnet today. You can also visit the or join the technical discussion on . Learn more by visiting the or follow them on or .
is a decentralized oracle network that enables smart contracts to securely access off-chain data feeds, web APIs, and traditional bank payments. It is well known for providing highly secure and reliable oracles to large enterprises (, , and ) and leading smart contract development teams such as , , , , , , and many others.
About 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 for dapps across 80+ blockchains - including Ethereum, Solana, Arbitrum, Optimism, Base, Polygon, Celo, Fantom, Gnosis, and Avalanche.
As demand for data in web3 continues to grow, The Graph enters a 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 , , , , , and . Join the community on The Graph’s , join technical discussions on The Graph’s .
oversees The Graph Network. The Graph Foundation is overseen by the . , , , , , and are eight of the many organizations within The Graph ecosystem.