-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ethers.BigNumber.from does not work with negative stringified bignumber #1010
Comments
The If your are serializing, you should consider using just In general, you should not expect stringify to work on arbitrary classes... Make sense? |
I understand that they are intended to be internal, so the workaround there is not too nice. I am using bigints in a bigger javascript object and its quite hand to be able to stringify whole thing and then get it back. The better workaround would be to iterate throught the structure and convert bigints using .toString(), or just use strings there all the time (but not as nice from dev experience perspective). Is there are reason JSON.stringify couldn't be made to work or why it wouldn't be supported? If the support is not wanted, it would be handy to have .from() reject "{ _hex: "0x01", _isBigNumber: true }" as well so this would'nt cause weird bugs where it sometimes work and sometimes not. |
I’ll look into adding a I plan to overhaul the internals of BigNumber, so relying on the above behaviour could just fail at some point in the future. I’m surprised that negative numbers don’t work (so I’ll prolly fix that too), but I’ll try getting a more sustainable solution in, in general. :) |
That sounds like a good plan! I appreciate it :) |
Added in 5.0.9. Let me know if it works for you. I've added JSON support to the BigNumber class as well as support negative Thanks! :) |
Closing this now, but if you have any issues, please re-open. Thanks! :) |
I have need to stringify a BigNumber and restore it. This seems to work with only with positive numbers and not negative
This fails:
while this works:
Also this fails:
while this works:
The workaround is to get the _hex string of the object and work with that, but I think it would be nice if this would work with the whole object.
The text was updated successfully, but these errors were encountered: