In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What is the calling method of Defi data engine The Graph? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
When you try to access Ethernet Square smart contracts and blockchain data generated by DApp, you may find it difficult to convert the data into a readable format. The Graph provides an index protocol for querying ethernet and IPFS network data, and anyone can create and publish index data, namely subgraph, based on the open API it provides, which makes the blockchain data easier to access. We will learn how to use The Graph to query Aave protocol data, including Graphql, JavaScript, and Nodejs.
1. Preparation for visiting The Graph
The first step in the tutorial is to visit the The Graph website and view the protocols that are currently supported, such as Uniswap, ERC20, Aave, Compound, and so on. If you find the protocol to which you want to extract data, such as Aave, click the protocol to enter:
The first thing you need to do is to write down the address (1) on the page, which you will query later. In our example, this address is: https://api.thegraph.com/subgraphs/name/aave/protocol.
The area (2) on the left shows an example of a query, which you can execute by clicking the [play] button. You can also modify the query example for other tests.
The area (3) on the right gives a description of the entities contained in the subgraph. Clicking on any of these entities gives a more detailed description of the entity, including its fields and relationships with other entities.
2. Construct GraphQL query statement
In the following example, we will construct a simple query to list the latest lightning loans on the Aave platform. The Graph's query uses GraphQL, and if you are not familiar with GrapQL, you can check out this tutorial.
Before we start writing GraphQL queries, we also need to understand how lightning loans are defined in graph. To do this, we can search the FlashLoan entity on the left to see what it contains:
Our query will find the latest 10 lightning loan records:
{flashLoans (first: 10, orderBy: timestamp, orderDirection: desc) {id reserve {name symbol} amount, target, timestamp}}
Notice that the lightning loan object points to another entity reserve, the repository.
3. Use NodeJS to submit GraphQL query
The Graph's user interface provides a great way to test and develop your own queries. Now it's time to implement queries in JavaScript (or any other language of your choice). This process is simple, we only need to submit the query statement to the https access node provided by The Graph through a HTTP POST request.
We use axios to process the request:
Npm install axios-save
The whole code looks like this:
Const axios = require ('axios') axios.post (' https://api.thegraph.com/subgraphs/name/aave/protocol', {query: `{flashLoans (first: 10, orderBy: timestamp, orderDirection: desc) {id reserve {name symbol} amount, target Timestamp}} `}) .then ((res) = > {for (const flashsloan of res.data.data.flashLoans) {console.log (flashsloan)}}) .catch ((error) = > {console.error (error)})
The execution result is similar to the following figure:
Using The Graph indexed data allows you to avoid listening to block chain events, decoding event parameters or dealing with token decimal point problems, development efficiency and system stability will be greatly improved.
After reading the above, have you mastered the method of calling Defi data engine The Graph? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 242
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.