Closed ArielGueta closed 1 month ago
parseUnits('115792089237316195423570985008687907853269984665640564039457584007913129.639936', 6)
is greater than the maximum uint256
value (2 ** 256 - 1
) so this is expected.
How it works for uniswap? any suggestion, please?
What do you need a suggestion for? Just don’t exceed the max uint256 range I guess.
@jxom The value 115792089237316195423570985008687907853269984665640564039457584007913129639935 is exactly the maximum value for a uint256. So why the code throws?
Ok, I see that there is some rounding issue.
115792089237316195423570985008687907853269984665640564039457584007913129639935 becomes 115792089237316195423570985008687907853269984665640564039457584007913129639936n
Ok, the issue solved, thanks
This issue has been locked since it has been closed for more than 14 days.
If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Viem version. If you have any questions or comments you can create a new discussion thread.
Check existing issues
Viem Version
^2.13.2
Current Behavior
When interacting with dApps such as Uniswap, large token approval amounts are often used. For example, the approval amount might be:
Using the
parseUnits(amount, decimals)
function converts this to:However, when trying to encode this amount for a transaction, the following code snippet:
results in an
IntegerOutOfRangeError
.Expected Behavior
The encodeTxData function should handle large integers without throwing an IntegerOutOfRangeError.
Steps To Reproduce
Use the parseUnits function with a large token approval amount:
Attempt to encode the transaction data with the parsed amount:
Link to Minimal Reproducible Example
No response
Anything else?
No response