question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why doesn't BigNumber.toString allow an arbitrary base?

See original GitHub issue

Hello, I’m getting this error when using @ethersproject/bignumber

bigNumber.toString does not accept parameters (code=UNEXPECTED_ARGUMENT, version=bignumber/5.0.1)

It’s coming from this toString() override where the comment indicates this is intentionally not supported: https://github.com/ethers-io/ethers.js/blob/d817416bae2fbc7adb8391fd038613241b7ab8ba/packages/bignumber/src.ts/bignumber.ts#L186

I’m wondering why is this not supported.

On the surface it looks like ethers could pipe the base and padding parameters to the underlying BN implementation, like so:

    toString(base: any, padding: any): string {
        return toBN(this).toString(base || 10, padding);
    }

What am I missing?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mirceaniscommented, Sep 5, 2020

I’m closing it since there was no time to dig deeper. I’ll reopen once I run into this again.

1reaction
ricmoocommented, Jul 19, 2020

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. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Please pass numbers as strings or BigNumber objects ...
The first way throws the error 'Unhandled Rejection (TypeError): Cannot read property 'toString' of undefined' - why is that? And the second one ......
Read more >
bignumber.js API - GitHub Pages
Returns a new instance of a BigNumber object with value n , where n is a numeric value in the specified base ,...
Read more >
Bignumber.js - JavaScripting
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.
Read more >
BigInteger Base Conversion - java - Stack Overflow
So in the above code I used String value = bigInteger.toString(finalBase) to return a String representation of the base10 BigInteger in the ...
Read more >
server - node_modules - bignumber.js - README.md - GitLab
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic. ... It also does not allow NaN or Infinity , or have the configuration ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found