-
-
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
Why doesn't BigNumber.toString allow an arbitrary base? #889
Comments
This has come up before, which is why that error was added, people passed things in, expecting it to work and it doesn't. :) There are a few reasons. I may forget some, but these are what come to mind. :) Firstly, this is not supported is because then it becomes something that must remain supported. Currently I use the BN.js library, but it is completely isolated (along with the elliptic package) so that in the future I can remove it without breaking anything. This might happen in the non-distant future, which would dramatically shrink the library, or at allow a dramatically smaller ES2020 version (which would become its own dist file). Also, the string values used for various bases (other than 10 and 16; 2 and 8 are as well, but are less interesting) are not well standardized or have multiple standards, and so become very hard to accurately present what everyone expects, and the need to possibly pad becomes complicated as well (as indicating padded bits becomes the next request) since it is also non-standardarized. In general it isn't a wonderful idea to overload the The BigNumber class only supports base-10 strings ( Any other base is generally not really Ethereum-related, so is better served by a more specialized big number library (which most will accept a base-10 string as input, so conversion is fairly simple). I try to keep ethers lean. :) I hope that helps. Feel free to rebut though. :) |
It's not about allowing an arbitrary base, this I'll try to condense all of this in a tiny project to show how the error manifests. |
There is no reason that anything expecting an ethers BigNumber should be passing in a parameter to You can convert the ethers BigNumber into a BN.js using |
Any luck with an example? I may close this soon otherwise... :s |
Not yet, thanks for reminding me. |
Cool cool. I’ll keep it open. Keep in mind ethers exposes absolutely zero parts of BN.js. It is not meant to be compatible with BN.js and BigNumber should be thought of as its own implementation of a big number library. There is no way to use any part of BN.js from any export in ethers. :) |
Any luck? Mind if I close this now? :) |
I'm closing it since there was no time to dig deeper. I'll reopen once I run into this again. |
Hello, I'm getting this error when using
@ethersproject/bignumber
It's coming from this
toString()
override where the comment indicates this is intentionally not supported:ethers.js/packages/bignumber/src.ts/bignumber.ts
Line 186 in d817416
I'm wondering why is this not supported.
On the surface it looks like ethers could pipe the
base
andpadding
parameters to the underlying BN implementation, like so:What am I missing?
The text was updated successfully, but these errors were encountered: