BigInt and Unit-Handling
Numbers in smart contracts are usually stored without decimals as big numbers, and a second variable contains information about the amount of decimals.
Some utility functions can help ease the handling of these numbers, especially with the bigint
support now being natively available:
Convert Token Balance to Human-Readable Version
For example, reading the balance of VTHO and turning it into a readable version:
Using unitsUtils.formatUnits(number, decimals)
, the number is turned into a string with the decimal right where a human needs it.
Convert Human Inputs to BigInts
When building user interfaces, numbers are entered as strings and need to be turned into BigInts for interaction with the blockchain.
unitsUtils.parseUnits(string, decimals)
helps in that way. For example:
Last updated