2

Logging a value from a contract with ethers.js, gets me this:

tokenBalance: v
  _hex: "0x033b2b2062ddfc98de7fffff"
  _ethersType: "BigNumber

Is this an instance of bn.js, bignumber.js or a custom implementation?

4

The ethers.js library uses BN.js internally for its maths, but the BigNumber class that is exposed serializes all values as immutable strings, and uses Object.defineProperty to ensure the resulting object is completely immutable. So, what you are seeing neither BN.js or bignumber.js. A custom implementation would probably be the best way to describe it, but that is being far too generous.

As a side note; the reason for using BN.js is that it is part of elliptic, so it required regardless, so rather than including a second Big Number library, it simply reuses the Big Number library that is required to be present anyways. :)

1

bn.js from the source code itself:

https://github.com/ethers-io/ethers.js/blob/4ac08432b8e2c7c374dc4a0e141a39a369e2d430/package.json#L23

"bn.js": "^4.4.0",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.