Bringing Indexed Data from The Graph to Smart Contracts with Chainlink Oracles
The Graph is excited to announce an integration with Chainlink, 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
Synthetix is an example of a DeFi dApp that combines the best of middleware protocols: using Chainlink oracles for price feeds and powering their exchange UI using a subgraph. 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 verifiable randomness. Being the most widely used oracle network 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. The Graph Oracle 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.” – Yaniv Tal, Co-founder at The Graph
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 here. They can help you quickly and securely launch your data-enabled application or Chainlink Price Reference Data Contract on mainnet today. You can also visit the developer documentation or join the technical discussion on Discord. Learn more by visiting the Chainlink website or follow them on Twitter or Reddit.
Chainlink 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 (Google, Oracle, and SWIFT) and leading smart contract development teams such as Polkadot/Substrate, Synthetix, Loopring, Aave, OpenLaw, Conflux, and many others.
About The Graph
The Graph is the indexing and query layer of the decentralized web. Developers build and publish open APIs, called subgraphs, that applications can query using GraphQL. There is a hosted service in production that makes it really easy for developers to get started building on The Graph and the decentralized network will be launching later this year. The Graph currently supports indexing data from Ethereum, PoA, and IPFS, with more networks coming soon. To date, over 1,500 subgraphs have been deployed by over 1,400 developers, for dApps like Uniswap, Synthetix, Aragon, AAVE, Gnosis, Balancer, Livepeer, DAOstack, AAVE, Decentraland and many others.
If you’re a developer building a dApp or Web3 application, use subgraphs for indexing and querying data from blockchains! The Graph allows dApps to efficiently and performantly present data in a UI and lets other developers use your subgraph too! You can deploy a subgraph or query existing subgraphs that can be found in the Graph Explorer. Join our community by introducing yourself in our Discord for technical discussion, join our Telegram chat or follow us on Twitter! Our developers are always eager to chat with you and The Graph ecosystem has a growing community of developers that support each other.
Note: chainlinkecosystem.com does not claim any ownership of this content, all credit to Graph Protocol, view official announcement.