[Ethereum] What big number library does ethers.js use

bignumberethers.js

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?

Best Answer

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

Related Topic