'uniswap V2 invalid BigNumber value for JSBI negative value

Hi I was following uniswapV2 document to perform a trade transaction and I encounter error as follow invalid bignumber value

I got my input amount as 2941991120 and in JSBI form it is -1352976176, which gave me invalid bignumber value bug. Here is my code code screenshot. But I was following exactly what the tutorial says https://uniswap.org/docs/v2/javascript-SDK/trading/

Can anyone tell me where I did wrong ?



Solution 1:[1]

The example tells you the value should be converted to hex:

const value = trade.inputAmount.raw // // needs to be converted to e.g. hex

Same for one of the other values. Have you tried this?

If you use a (signed) integer, its sign can be positive/negative (+/-). Whatever value you're sending is deemed to be a negative one, which is unexpected and so the response is telling you.

This exmaple seems to suggest you can do: https://ethereum.stackexchange.com/questions/87983/failed-transaction-error-encountered-during-contract-execution-on-uniswap-rout

...
const amountOutMinHex = ethers.BigNumber.from(amountOutMin.toString()).toHexString();
...

Solution 2:[2]

The JSBI::toString() method takes a radix parameter, so your linked example would look like:

trade.minimumAmountOut(slippageTolerance).raw.toString(16);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Joe Coder