uniswap V2 invalid BigNumber value for JSBI negative value

Viewed 1660
2 Answers

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();
...

The accepted answer is unnecessarily complex. The JSBI::toString() method takes a radix parameter, so your linked example would simply look like:

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