Unable to understand why Block chain uses before decimal point uses 8 zeros. As far as ETH its Giga Wei and satoshi for bitcoin. But why we use so many zeros?
1 Answer
Representing floating point numbers and doing float arithmetic in code is funky. We prefer to use integers (in solidity's case, unsigned 256 bit integers, uint256
).
As such, 1 unit of value in Ethereum (for example, msg.value==1
in the context of a transaction) in reality represents the smallest amount of Ethereum available for calculation: 1 wei, or 10^(-18)
Ethers.
To help with arithmetic, solidity also employs helpers as global variables, such as:
msg.value = 1 wei; //This is 1:1 with what I just described
msg.value = 2 gwei //This is equivalent to 2 * 1e9 weis
msg.value = 3 ether // This is equivalent to 3 * 1e18 weis, 3 full ethers
You can read up more on it, as well as the philosophy behind it, in the solidity docs here: https://docs.soliditylang.org/en/v0.8.14/units-and-global-variables.html