如何从我的 UNISWAP FACTORY 查询数据? (GQL)

发布于 2025-01-16 12:33:59 字数 1163 浏览 1 评论 0原文

我想在我的合约中获取一对的前 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2025-01-23 12:33:59

这些图表特定于它们所在的链。这是一个主网图。我不知道 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文