Closed LogvinovLeon closed 6 years ago
First, I wanted an immutable BigNumber. Often times when calling an operation, like sendTransaction, there is a number of steps, à la Promises executed, so by the time serialization actually occurs, someone could have changed the value, maliciously or by accident. By making them immutable, I can save code and effort, and pass them along.
I also wanted to abstract it, offering only what was needed, so in the future if I decide to swap it out, I only need to implement the functionality I require. For example, I would not want to implement RED myself, and since outside of ECC, it is unused, so if I just handed over the BN.js, to maintain backward compatibility, someone might have used it, so I would need to keep that going forward.
BigNumbers are a fairly fundamental part of an Ethereum library, so I wanted more control over them. I wanted an easier to use API, which I believe BigNumber provides, through its BigNumberish input parameters. I find it, personally, saves me a lot of time and code, compared to using BN.js directly.
As a side note, the reason it wraps BN.js, is that BN.js is used by elliptic, so it is absolutely required, regardless to use secp256k1. So, this reduced the code size a lot. But if, for example, there was a version of ethers without signing (or delegated signing and recovery), the BigNumber library could be massively reduced, since it only supports the subset of features required, as RED and combs could be removed.
Closing this now, but please feel free to continue discussion (I still monitor closed tickets), or feel free to re-open. :)
Hello, I'm using both ethers and bn.js in my project. Is there a way to convert a value bigNumberify by ethers into a bn.js BigNumber ?
The easiest way to do conversion is using the base-10 string:
// bn => BigNumber
let u = ethers.utils.bigNumberify(someBn.toString());
// BigNumber => bn
let v = new bn(someBigNumber.toString());
Let me know if there are any issues with that. :)
@PierreJeanjacquot (just tagging you so you can see the above answer ;))
@ricmoo ok thanks for your answer :)
Why does ethers.js use a custom-written bn.js wrapper? I know some tools in the community use BigNumber and some others use bn.js, but taking bn.js wrapping it in a restrictive way, converting it back and force on every operation between bn and hex forms and calling it BigNumber to have colliding names with an existing and popular library seems like a strange decision to me.