How to query data from my UNISWAP FACTORY? (GQL)

660 Views Asked by At

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?

1

There are 1 best solutions below

1
On

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