The Graph is an important Web3 infrastructure protocol that makes it easy to query blockchain data. By indexing and organizing data from networks like Ethereum, The Graph creates open APIs that developers can use to build blockchain applications. Learning how to leverage The Graph is key for accessing on-chain information.
Hosted and Custom APIs: Accessing Blockchain Data
The Graph uses a system of Curators, Indexers, and Delegators to index and store data from various blockchain networks. Curators signal which data should be indexed by staking the native GRT token. Indexers then query and process this data, making it available through the hosted subgraph APIs. Delegators can assign GRT tokens to Indexers as a sign of confidence in their work. As an end-user looking to query blockchain data, The Graph exposes both hosted and custom APIs:
Hosted APIs are public subgraphs created by Indexers to provide data sets for popular protocols like Uniswap, Aave, Decentraland, and more. These can be queried immediately using sample queries provided in The Graph Explorer playground.
Custom APIs can be created by developers to index blockchain data tailored to their specific application needs. This involves deploying your own smart contracts that encode how data should be indexed on the blockchain itself.
Using the hosted APIs on The Graph is the most straightforward way to start querying blockchain data. As an example, to look up information on Uniswap V2 pairs, you would first find the Uniswap subgraph under Hosted Services in The Graph Explorer.
Utilizing The Graph: Harnessing Blockchain Data for Web3 Development
Then, in the example queries, you can copy over the query that retrieves ‘Pair Created’ events to view newly created Uniswap pairs. Hitting “Run Query” will fetch all V2 pairs and return data like each pair’s ID, asset tokens, reserves, and other attributes. You can also modify the query to filter the results or specify different fields for the pairs of entities you want to display. Overall, The Graph-hosted APIs provide a simple method to start pulling valuable on-chain data.
Similarities between GraphQL and the Graph query language may be seen in its capability for nested data lookups and returns. To prevent timeouts and excessive response sizes while retrieving huge data sets from The Graph,
Hosted APIs make available robust public data, but custom subgraphs enable even more sophisticated manipulation. In order to categorize and respond to unanticipated events, developers can include data processing logic. Creating specialized subgraphs does call on solid knowledge and the use of The Graph network’s resources.
The data stored in the blockchain is unlocked by The Graph and may be used to improve Web2 and Web3 apps. The Graph, with its powerful querying and data API creation features, is set to become a cornerstone of the decentralized web. Anyone can start using on-chain data to create enhanced blockchain experiences by following the instructions in this guide.