Add a .toBigInt() method to BigNumber type
See original GitHub issueEthers accepts BigInt’s as inputs for BigNumberish types, but getting a BigInt from a returned BigNumber is a bit clunky with BigInt(myBigNumber.toString())
I saw in https://github.com/ethers-io/ethers.js/issues/594#issuecomment-526807810 you mentioned that “There will likely be an instance method that will return a BigInt (similar to the instance.toNumber())”, though that method still doesn’t exist.
I’m happy to submit a PR for it, as long as you still support adding an instance.toBigInt() method, and my only question would be whether to throw or return null on platforms that don’t support BigInt
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
BigNumber - ethers
A BigNumber is an object which safely allows mathematical operations on numbers of any magnitude. Most operations which need to return a value...
Read more >BigInt - JavaScript - MDN Web Docs
The best way to achieve nearly the same effect in JavaScript is through the BigInt() function: BigInt(x) uses the same algorithm to convert ......
Read more >bignumber.js API
The following is an example of how to add a prototype method that emulates JavaScript's Math.round function. Math.ceil , Math.floor and Math.trunc can...
Read more >How to convert strings to bigInt in JavaScript - Stack Overflow
You can use a JavaScript lib called BigInteger.js for the purpose.it is an arbitrary-length integer library for Javascript, ...
Read more >BigDecimal toBigInteger() Method in Java - GeeksforGeeks
math.BigDecimal.toBigInteger() is an inbuilt method in java that converts this BigDecimal to a BigInteger. This conversion is analogous to the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This should now be available in 5.1.0.
Try it out and let me know if there are any issues. 😃
I have a bunch of other changes I’m pushing out today with v5.1, and this is something that makes sense for that minor bump. I’ll add it today. 😃