2

I have a project that tries to retrieve real time data from UnisWap V2 and SushiSwap I have already figured out how to get real time data from Sushi using api but it's not the same for Uniswap API since when you try to get data using query it doesn't really give you real time data its just giving you imitation and I found out that to get real time data using api you have to use subscription instead of query with 'thegraph.com' but I couldn't figure out how can I get subscription. maybe anyone has any idea how can I do that or is there any paid or free methods that I can use to get real time data from uniswap V2 ?

-S

2
  • Could you pls explain how to call contract itself? What do I need for this? Are you checking mempool from node js?
    – newbeee
    Commented Apr 10, 2023 at 11:33
  • I subscribe to contract and use latest blocks to console log reserves every time that its changed!
    – Said
    Commented Apr 10, 2023 at 12:35

3 Answers 3

3

You can use smart contract logs of emitted events to retrieve a stream of real-time logs emitted by the Uniswap smart contract.

You have two options:

  1. Use the eth_newFilter method combined with eth_getfilterChanges.

    eth_newFilter allows you to set up a filter for logs, then eth_getfilterChanges will give you the new data emitted. Note that you have to query eth_getfilterChanges at regular intervals.

You can find explanations and examples about these two methods on the Chainstack dev portal:

  1. The second option is using a WebSocket connection to receive a continuous stream of real-time data. You can either use eth_subscribe or the subscription methods native to web3.js.

You can find explanations and examples about these two methods on the Chainstack dev portal:

Another effective way to get Uniswap data is by indexing the data coming from the smart contracts using Subgraphs. Chainstack just launched Subgraphs support, and there is a comprehensive guide on how to index Uniswap data!

Indexing Uniswap data

1

So I figured that the best way to get real-time data from uniswap v2 is to use WebSocket and subscribe to uniswap contract and read new data everytime new block is mined this is free and fast way of getting real time data... while api works as well sometimes it could be out of date and you will recieve outdated data in your project so It is better to call contract itself ...

0

Bitquery has a subscription feature, you can use it to get Uniswap trades in real time. Here's the graphql query https://ide.bitquery.io/Realtime-Uniswap-v3-trades

You can get the code for the query in any language, https://docs.bitquery.io/docs/ide/code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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