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 ?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With