如何从我的 UNISWAP FACTORY 查询数据? (GQL)
我想在我的合约中获取一对的前 10 次掉期。 我读到可以从 uniswap 的子图中获取: https://api.thegraph.com/subgraphs/name/uniswap/uniswap- v2 这是一个从主网获取一对的示例(我正在测试网上)
let url = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2';
const FIRST_TEN = `{
swaps(first: 10, where: { pair: "0x43ae24960e5534731fc831386c07755a2dc33d47" } orderBy: timestamp, orderDirection: desc) {
transaction {
id
timestamp
}
id
pair {
token0 {
id
symbol
}
token1 {
id
symbol
}
}
amount0In
amount0Out
amount1In
amount1Out
amountUSD
to
}
}
`;
const json = {
"query": FIRST_TEN
}
let xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.responseText);
}
};
xhr.send(JSON.stringify(json));
它运行良好,但是一旦我输入我的对地址 - 它就找不到任何交换。 (我的配对在 ROPSTEN 网络中),它仅适用于主网吗?
I want to fetch first 10 swaps of a pair , in my contract.
I've read that its possible to fetch from the subGraph of uniswap:
https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2
Here is an example to fetch a pair from the MAINNET (Im working on a testnet)
let url = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2';
const FIRST_TEN = `{
swaps(first: 10, where: { pair: "0x43ae24960e5534731fc831386c07755a2dc33d47" } orderBy: timestamp, orderDirection: desc) {
transaction {
id
timestamp
}
id
pair {
token0 {
id
symbol
}
token1 {
id
symbol
}
}
amount0In
amount0Out
amount1In
amount1Out
amountUSD
to
}
}
`;
const json = {
"query": FIRST_TEN
}
let xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.responseText);
}
};
xhr.send(JSON.stringify(json));
It's working good , but as soon as I put my pair address - it doesn't find any swaps. (my pair is in the ROPSTEN network) , is it working only for the MAINNET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些图表特定于它们所在的链。这是一个主网图。我不知道 ropsten 是否有图表,据我所知,uniswap 没有图表。我确实知道 goerli 图,但是测试网没有维护,所以不会有很多好的信息。
https://thegraph.com/hosted-service/subgraph/ianlapham/ uniswap-v3-gorli
The graphs are specific to the chain they are on. That is a main net graph. I don't know if ropsten has a graph, none by uniswap afaik. I do know of a goerli graph, however testnets are not maintained, so there won't be a lot of good info.
https://thegraph.com/hosted-service/subgraph/ianlapham/uniswap-v3-gorli