Hey guys I am using the Uniswap Javascript SDK and Ethers JS to make a swap but I am getting this

Error: invalid BigNumber value (argument="value", value=[-626648004,3158], code=INVALID_ARGUMENT, version=bignumber/5.1.1)

This is my code:

            await window.ethereum.enable();
            let provider = new ethers.getDefaultProvider('ropsten');
            const signer =  (new ethers.providers.Web3Provider(window.ethereum)).getSigner();

            const amountIn = '1000000000000000000'; // 1 WETH

            const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
            const DENT = new Token(ChainId.ROPSTEN, "0xa51f5e00b3a454ba56c4add590d5cfeb2d197ae0", 8);
            const pair = await Fetcher.fetchPairData(DENT, WETH[DENT.chainId]);

            const route = new Route([pair], WETH[DENT.chainId]);

            const trade = new Trade(route,  new TokenAmount(WETH[DENT.chainId], amountIn),  TradeType.EXACT_INPUT);

            const slippageTolerance = new Percent('50', '10000');  // 50 bips, or 0.50%

            const amountOutMin = trade.minimumAmountOut(slippageTolerance).raw; // needs to be converted to e.g. hex
            const path = [WETH[DENT.chainId].address, DENT.address];
            const to =  accounts[0]; // should be a checksummed recipient address

            const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes from the current Unix time
            const value = trade.inputAmount.raw;  // // needs to be converted to e.g. hex

            const account = signer.connectUnchecked(provider);

            const uniswap = new ethers.Contract('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',['function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)'], account);
            const tx = await uniswap.swapExactETHForTokens(amountOutMin, path, to, deadline, {value: value, gasPrice: 20e9});

I tried using the ether's BigNumber constructor but I still got the same error. Does anyone know what's going on?

2 Answers 2


I had the same issue and it took me quite a while to find the root cause of this as the errors' messages were not super helpful.

Simply convert the amountOutMin and value values to String like this:

const tx = await uniswap.swapExactETHForTokens(
      { value: String(value), gasPrice: 20e9 }

It should work like a charm now (:


the error you're getting is because somewhere in your code [-626648004,3158] value is being passed.

Can you tell which line is giving that error or provide the stack trace? That information can help us help you :)

Also, if you found the line which gives error, can you console.log in your JS code the variable inputs involved in that line, one of them should be [-626648004,3158].

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.