DEV Community

HassanHabibTahir
HassanHabibTahir

Posted on

BigNumbers

BigNumber is an object which safely allows mathematical operations on numbers of any magnitude
uint256 has a range from 0 to (2^256) - 1. Therefore, the maximum number that can be held by the uint256 datatype is astronomically large.
Specifically, the maximum value for uint256 is:
115792089237316195423570985008687907853269984665640564039457584007913129639935

In Javascript's number data type has a significantly smaller upper limit.
Specifically, the maximum value of a numeric type that Javascript can hold is just
(9007199254740991);

If that number is greater than Javascript's maximum numeric value, which is quite definitely possible, then what happens?
Javascript can not support that. Therefore, we have to use a special type called a BigNumber.
ibraries used for interacting with Ethereum nodes - ethers.js and web3.js - both come with support for BigNumbers.

BigNumber is a custom class library, written in Javascript, that introduces it's own functions for mathematical functions - add, sub, mul, div, etc. BigNumber has a significantly larger capacity for numbers than what Javascript can natively support.

Top comments (0)