I want to expect how much input tokens should be spent to get exact amount of output token on Uniswap V3. Uniswap V2 has router.getAmountsIn() to expect it. V3 supports quote interface but it is supposed to be called from off-chain only.

If it's impossible, I want rough value too. So I want to calculate A to get B. In some way, we got rough value A. A -> B', B' >= B, B'- B -> 0

  • hello bro. Did u figured out how to do on chain? please help Commented Nov 11, 2023 at 13:37
  • @BirukDamte, I've just posted an answer to my problem.
    – intelmin
    Commented Nov 12, 2023 at 14:38

2 Answers 2


The formula is laid out in the SDK documentation. You need to read the slot0 value from the UniswapV3Pool contract of the pair you are interested in. The first uint160 value returned in the sqrtPrice96X. Then depending on which token price of the two you want you either use:

price = sqrtRatioX96 ** 2 / 2 ** 192


price = 2 ** 192 / sqrtRatioX96 ** 2



Uniswap has their own on-chain solution for quoting prices now.


  • tnx a lot brother Commented Nov 14, 2023 at 13:46
  • Do you have an example where this is deployed and in use? Feel like I've only seen v1/v2 quoters in the wild.
    – Maka
    Commented Nov 17, 2023 at 16:21
  • I am not sure if they have a deployed one for product version. Rather I think they are still in staging phase, Anyway they say, the interfaces are same as V2, so for now it'd be better to go with V2 contracts and later we will be able to upgrade easily.
    – intelmin
    Commented Nov 19, 2023 at 3:32
  • Any idea how to implement the Quoter? Looks like importing is not viable cause all the files are made for 0.7.6 compiler.
    – user130657
    Commented Mar 23 at 21:26
  • Why don't you simiply upgrade the version to latest? Or Uniswap now provides quote apis, which you could bring the quoted data to on-chain using Oracle.
    – intelmin
    Commented Mar 25 at 16:22

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.