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?


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. :)


bn.js from the source code itself:


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