When I tried to swap 1BAT from DAI by using Uniswap App (https://app.uniswap.org/#/swap), I needed 0.325372DAI as this picture show.

enter image description here

However, when I tried to calculate how much DAI I need to get 1BAT by directory read contract function (getAmountsIn()), it shows 329322487172572064, which means I need '0.32932DAI' to swap 1BAT. enter image description here

I thought that the amount from getAmountsIn() would be same as the amount from uniswap official app. Why those two amounts are different, Did I called wrong function? Could you give me any advise, please?

3 Answers 3


As far as I was aware, this difference is the fee paid to the Liquidity Pool creators. That is, the reward for locking up these funds to create the market via the liquidity pool.

  • Thank you for your comment. In your case, do you know how to get the same amount (0.325372DAI) which is from Uniswap official app by directory calling contract function?
    – gnxvw
    Commented Aug 21, 2020 at 5:34

When you try to exchange something using Uniswap web application, the application runs a path finder algorithm between different pairs and depending on the amount you want to swap it suggest the path with best exchange ratio. As it is clear in the photo, the router algorithm suggested DAI-USDT + USDT-BAT path for your swap.

If you want to regenerate the same output using only contract call, you have to input the same path which in your case would be:

[0x6b175474e89094c44da98b954eedeac495271d0f, 0xdac17f958d2ee523a2206206994597c13d831ec7, 0x0d8775f648430679a709e98d2b0cb6250d2887ef]


getAmountsIn() already account for fees. However, if there is no direct liquidity for the pair you are trading, you have to use a path connecting multiple liquidity pools. Different paths will yield different results. The exchange app calculate the optimal route, therefore, in order to obtain the same result calling the contract function directly, you must provide an optimal route too.

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.