4

I am using the Uniswap v2 api subgraph but I am running into a bit of an issue that I cannot resolve.

Basically I want to query the api to get the latest token swaps of a chosen token and Eth. Using Eth's current price I can accurately get a real-time price of the given token.

But in order to make pair information requests to the api you need to know the pair ID to begin with.

How can I possibly get the pair ID if the pair ID is not stored or apart of the chosen token's id? I can dynamically get the token's ID from another API and I can use that to query info from Uniswap's api however there seems to be no way to get the actual pairs ID in order to determine the latest swaps.

Here is a sandbox of Uniswaps subgraph API in case anyone wants to try and see if they can pull a coin's pair ID address.

https://thegraph.com/explorer/subgraph/uniswap/uniswap-v2

Edit: to be clear I can get the Pair ID addresses manually by going to uniswap.info however this is not what I want to do. I want to be able to dynamically search for any erc-20 token and then use that token to pull the latest swaps using the pair ID.

4
  • +1 , I'm also looking for the same thing. There's Token.mostLiquidPairs, but it always returns an empty array. If you find out something, I'd appreciate you nudging me. Thanks!
    – ecif
    Jan 15 at 9:19
  • Alternatively, there's uniswap discord channel > UNISWAP-DEVELOPERS > #subgraph-api discord.gg/Ze3dRdHKWV
    – ecif
    Jan 15 at 11:23
  • 2
    @ecif Hey, so I've come to realize that there is currently no way to get the pairs ID dynamically though any api calls. And I also did query the mostLiquidPairs field and got empty array back. I also did pose this question on the Uniswap discord already and the response back was in line with what I wrote; there is no way to get it. However there is another way to do what I want to do and but I haven't implemented it yet. You can query AllPairs from Uniswap api and then store it in a collection then you can iterate/search for your token ids to figure out which pairs you want to pull.
    – setup369
    Jan 15 at 21:04
  • @ecif If you figure out a more elegant way to do this please let me know. I'm using front end framework (reactjs) so querying allPairs is difficult since I cannot store persistent state using react. If I could just download a json of all the 30k plus Uniswap pair IDs instead it would be super helpful. If anyone reading this has that list please share! Thanks.
    – setup369
    Jan 15 at 21:07
2

You can write a query to filter all the liquidity pairs on Uniswap and get the pair address

    {  pairs (where :{token0 : "0x0f7f961648ae6db43c75663ac7e5414eb79b5704", token1 :"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}) { // token1 is the ethereum address
    id
    createdAtTimestamp
    volumeUSD
    //any other field you want
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.