Following the documentation here: https://uniswap.org/docs/v2/javascript-SDK/pricing/

I have been able to replicate the results using WETH, and I have decided to have a go at getting a similar result with DAI and USDT.

const { ChainId, Fetcher, Route, Trade, TokenAmount, TradeType, WETH } = require('@uniswap/sdk');

const init = async () => {
    const dai = await Fetcher.fetchTokenData(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F');
    const tether = await Fetcher.fetchTokenData(ChainId.MAINNET, '0xdAC17F958D2ee523a2206206994597C13D831ec7');
    const pair = await Fetcher.fetchPairData(dai, tether);
    const route = new Route([pair], tether);

    const trade = new Trade(route, new TokenAmount(tether, '1000000000000000000'), TradeType.EXACT_INPUT);


I retrieve the Token Data for both Dai and Tether, then fetch pair data which I then put into a route.

These abovementioned steps must be correct as the an in-function log of


return values that make sense.

Where things become odd is with


According to these results, my price impact is at 100, the execution price is around 0.000000278029, and the output amount is at 278028.

This doesn't sound right at all.

What is the mistake in my code that brings about this error?

  • Has this been resolved for you? I have exactly the same problem -- ETH/DAI pairs work fine, but USDX/PAX returns nonsense compared to what the uniswap web site shows? Jul 2, 2021 at 5:24

1 Answer 1


There is a decimal mistake in the TokenAmount. It is important to check how many decimals any specific token has. While 1000000000000000000 wei is 1 ether, 1000000000000000000 specified for USDT, which has 6 decimal places, would equal 1000000000000, which is much greater than the current liquidity supply on Uniswap. 1000000 specified for USDT would equal 1 USDT and return reasonable results for

  • Anyway to calculate max to buy / too big price impact? I have a Solidity contract that use it's ether to buy X token using swapExactETHForTokens. But I don't find how I can make it to use the MAX possible eth so that uniswap let my transaction go without revert.
    – btc4cash
    Oct 17, 2020 at 18:19
  • @Vasya I use the same method to quote the price of other token pairs (e.g. LINK/DAI), but it returns absolutely irrelevant results (compared to prices on Uniswap website). Do you have any idea about that? Feb 14, 2021 at 9:09

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.