<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/best-practices/">Best Practices</a></div><divclass="base show link depth-1"><ahref="/v5/api-keys/">Provider API Keys</a></div><divclass="base ancestor show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="show link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="show link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="ancestor show link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/coder/">AbiCoder</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/formats/">ABI Formats</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="myself ancestor ancestor show link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="link show child depth-4"><ahref="#BigNumber--types">Types</a></div><divclass="link show child depth-4"><ahref="#BigNumber--creating">Creating Instances</a></div><divclass="link show child depth-4"><ahref="#BigNumber--methods">Methods</a></div><divclass="link show child depth-4"><ahref="#BigNumber--notes">Notes</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="show link depth-2"><ahre
<aname="BigNumber"></a><aname="BigNumber"></a><h1class="show-anchors"><div>BigNumber<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber"></a></div></div></h1><p>Many operations in Ethereum operation on numbers which are <ahref="/v5/api/utils/bignumber/#BigNumber--notes-safenumbers">outside the range of safe values</a> to use in JavaScript.</p>
<aname="BigNumberish"></a><aname="BigNumber--BigNumber--types--BigNumberish"></a><h3class="show-anchors"><div>BigNumberish<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumberish"></a></div></div></h3><p>Many functions and methods in this library take in values which can be non-ambiguously and safely converted to a BigNumber. These values can be specified as:</p>
<divclass="definition"><divclass="term"><b><i>string</i></b></div><divclass="body"><p>A <ahref="/v5/api/utils/bytes/#HexString">HexString</a> or a decimal string, either of which may be negative.</p>
</div></div><divclass="definition"><divclass="term"><b><i>BytesLike</i></b></div><divclass="body"><p>A <ahref="/v5/api/utils/bytes/#BytesLike">BytesLike</a> Object, such as an Array or Uint8Array.</p>
</div></div><divclass="definition"><divclass="term"><b><i>number</i></b></div><divclass="body"><p>A number that is within the <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER#Description">safe range</a> for JavaScript numbers.</p>
</div></div><divclass="definition"><divclass="term"><b><i>BigInt</i></b></div><divclass="body"><p>A JavaScript <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt">BigInt</a> object, on environments that support BigInt.</p>
</div></div><aname="BigNumber--creating"></a><aname="BigNumber--BigNumber--creating"></a><h2class="show-anchors"><div>Creating Instances<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--creating"></a></div></div></h2><p>The constructor of BigNumber cannot be called directly. Instead, Use the static <codeclass="inline">BigNumber.from</code>.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">from</span><spanclass="symbol">(</span><spanclass="param">aBigNumberish</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"></div></div><divclass="body"><p>Returns an instance of a <b>BigNumber</b> for <i>aBigNumberish</i>.</p>
</span></div><aname="BigNumber--methods"></a><aname="BigNumber--BigNumber--methods"></a><h2class="show-anchors"><div>Methods<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--methods"></a></div></div></h2><p>The BigNumber class is immutable, so no operations can change the value it represents.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">add</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L75">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i><b>+</b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">sub</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L79">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i><b>-</b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">mul</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L91">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i><b>×</b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">div</span><spanclass="symbol">(</span><spanclass="param">divisor</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L83">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i><b>÷</b><i>divisor</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">mod</span><spanclass="symbol">(</span><spanclass="param">divisor</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L95">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of the <b>remainder</b> of <i>BigNumber</i>÷<i>divisor</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">pow</span><spanclass="symbol">(</span><spanclass="param">exponent</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L103">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i> to the power of <i>exponent</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">abs</span><spanclass="symbol">(</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L68">source</a></div></div><divclass="body"><p>Returns a BigNumber with the absolute value of <i>BigNumber</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">mask</span><spanclass="symbol">(</span><spanclass="param">bitcount</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L135">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i> with bits beyond the <i>bitcount</i> least significant bits set to zero.</p>
</div></div><aname="BigNumber--BigNumber--methods--two-s-complement"></a><h3class="show-anchors"><div>Two's Complement<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--BigNumber--methods--two-s-complement"></a></div></div></h3><p><ahref="https://en.wikipedia.org/wiki/Two%27s_complement">Two's Complement</a> is an elegant method used to encode and decode fixed-width signed values while efficiently preserving mathematical operations. Most users will not need to interact with these.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">fromTwos</span><spanclass="symbol">(</span><spanclass="param">bitwidth</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L60">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i> converted from twos-complement with <i>bitwidth</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">toTwos</span><spanclass="symbol">(</span><spanclass="param">bitwidth</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L64">source</a></div></div><divclass="body"><p>Returns a BigNumber with the value of <i>BigNumber</i> converted to twos-complement with <i>bitwidth</i>.</p>
</div></div><aname="BigNumber--BigNumber--methods--comparison-and-equivalence"></a><h3class="show-anchors"><div>Comparison and Equivalence<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--BigNumber--methods--comparison-and-equivalence"></a></div></div></h3>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">eq</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L156">source</a></div></div><divclass="body"><p>Returns true if and only if the value of <i>BigNumber</i> is equal to <i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">lt</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L160">source</a></div></div><divclass="body"><p>Returns true if and only if the value of <i>BigNumber</i><b><</b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">lte</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L164">source</a></div></div><divclass="body"><p>Returns true if and only if the value of <i>BigNumber</i><b>≤</b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">gt</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L168">source</a></div></div><divclass="body"><p>Returns true if and only if the value of <i>BigNumber</i><b>></b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">gte</span><spanclass="symbol">(</span><spanclass="param">otherValue</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L172">source</a></div></div><divclass="body"><p>Returns true if and only if the value of <i>BigNumber</i><b>≥</b><i>otherValue</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">isZero</span><spanclass="symbol">(</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L180">source</a></div></div><divclass="body"><p>Returns true if and only if the value of <i>BigNumber</i> is zero.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">toNumber</span><spanclass="symbol">(</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">number</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L184">source</a></div></div><divclass="body"><p>Returns the value of <i>BigNumber</i> as a JavaScript value.</p>
<p>This will <b>throw an error</b> if the value is greater than or equal to <i>Number.MAX_SAFE_INTEGER</i> or less than or equal to <i>Number.MIN_SAFE_INTEGER</i>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">toString</span><spanclass="symbol">(</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L193">source</a></div></div><divclass="body"><p>Returns the value of <i>BigNumber</i> as a base-10 string.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">toHexString</span><spanclass="symbol">(</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L210">source</a></div></div><divclass="body"><p>Returns the value of <i>BigNumber</i> as a base-16, <codeclass="inline">0x</code>-prefixed <ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">BigNumber</span><spanclass="symbol">.</span><spanclass="method">isBigNumber</span><spanclass="symbol">(</span><spanclass="param">object</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L284">source</a></div></div><divclass="body"><p>Returns true if and only if the <i>object</i> is a BigNumber object.</p>
</span></div><aname="BigNumber--notes"></a><aname="BigNumber--BigNumber--notes"></a><h2class="show-anchors"><div>Notes<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--notes"></a></div></div></h2><p>This section is a for a couple of questions that come up frequently.</p>
<aname="BigNumber--notes-safenumbers"></a><aname="BigNumber--BigNumber--notes--BigNumber--notes-safenumbers"></a><h3class="show-anchors"><div>Why can't I just use numbers?<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--notes-safenumbers"></a></div></div></h3><p>The first problem many encounter when dealing with Ethereum is the concept of numbers. Most common currencies are broken down with very little granularity. For example, there are only 100 cents in a single dollar. However, there are 10<sup>18</sup><b>wei</b> in a single <b>ether</b>.</p>
<p>JavaScript uses <ahref="https://en.wikipedia.org/wiki/Double-precision_floating-point_format">IEEE 754 double-precision binary floating point</a> numbers to represent numeric values. As a result, there are <i>holes</i> in the integer set after 9,007,199,254,740,991; which is problematic for <i>Ethereum</i> because that is only around 0.009 ether (in wei), which means any value over that will begin to experience rounding errors.</p>
<p>To demonstrate how this may be an issue in your code, consider:</p>
<p>The functions <ahref="/v5/api/utils/display-logic/#utils-parseEther">parseEther( etherString )</a> and <ahref="/v5/api/utils/display-logic/#utils-formatEther">formatEther( wei )</a> can be used to convert between string representations, which are displayed to or entered by the user and Big Number representations which can have mathematical operations handled safely.</p>
<aname="BigNumber--BigNumber--notes--why-not-bignumber-js-bn-js-bigdecimal-etc"></a><h3class="show-anchors"><div>Why not BigNumber.js, BN.js, BigDecimal, etc?<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--BigNumber--notes--why-not-bignumber-js-bn-js-bigdecimal-etc"></a></div></div></h3><p>Everyone has their own favourite Big Number library, and once someone has chosen one, it becomes part of their identity, like their editor, vi vs emacs. There are over 100 Big Number libraries on <ahref="https://www.npmjs.com/search?q=bignumber">npm</a>.</p>
<p>One of the biggest differences between the Ethers <ahref="/v5/api/utils/bignumber/">BigNumber</a> object and other libraries is that it is immutable, which is very important when dealing with the asynchronous nature of the blockchain.</p>
<p>Capturing the value is not safe in async functions, so immutability protects us from easy to make mistakes, which is not possible on the low-level library's objects which supports myriad in-place operations.</p>
<p>Second, the Ethers <ahref="/v5/api/utils/bignumber/">BigNumber</a> provides all the functionality required internally and should generally be sufficient for most developers while not exposing some of the more advanced and rare functionality. So it will be easier to swap out the underlying library without impacting consumers.</p>
<p>For example, if <ahref="https://www.npmjs.com/package/bn.js">BN.js</a> was exposed, someone may use the greatest-common-denominator functions, which would then be functionality the replacing library should also provide to ensure anyone depending on that functionality is not broken.</p>
<aname="BigNumber--BigNumber--notes--why-bn-js"></a><h3class="show-anchors"><div>Why BN.js??<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--BigNumber--notes--why-bn-js"></a></div></div></h3><p>The reason why <ahref="https://www.npmjs.com/package/bn.js">BN.js</a> is used internally as the big number is because that is the library used by <ahref="https://www.npmjs.com/package/elliptic">elliptic</a>.</p>
<p>Therefore it <b>must</b> be included regardless, so we leverage that library rather than adding another Big Number library, which would mean two different libraries offering the same functionality.</p>
<p>This has saved about 85kb (80% of this library size) of library size over other libraries which include separate Big Number libraries for various purposes.</p>
<aname="BigNumber--BigNumber--notes--allow-us-to-set-a-global-big-number-library"></a><h3class="show-anchors"><div>Allow us to set a global Big Number library?<divclass="anchors"><aclass="self"href="/v5/api/utils/bignumber/#BigNumber--BigNumber--notes--allow-us-to-set-a-global-big-number-library"></a></div></div></h3><p>Another comment that comes up frequently is the desire to specify a global user-defined Big Number library, which all functions would return.</p>
<p>This becomes problematic since your code may live along side other libraries or code that use Ethers. In fact, even Ethers uses a lot of the public functions internally.</p>
<p>If you, for example, used a library that used <codeclass="inline">a.plus(b)</code> instead of <codeclass="inline">a.add(b)</code>, this would break Ethers when it tries to compute fees internally, and other libraries likely have similar logic.</p>
<p>But, the <ahref="/v5/api/utils/bignumber/">BigNumber</a> prototype is exposed, so you can always add a <codeclass="inline">toMyCustomBigNumber()</code> method to all <ahref="/v5/api/utils/bignumber/">BigNumber</a>'s globally which is safe.</p>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on February 8, 2021, 3:25pm.</div>