2.15 Solidity Units
Ether Units
Ether is decimals, the smallest unit is a wei. There are various names given for different numbers of weis: gwei wei, Ether .
In the case of the Solidity
types, a literal number can be given a suffix of a wei, or a gwei (gigawei) or an Ether. These are used to specify sub denominations of Ether, as we see here, which are used when contracts want to manipulate different denominations of Ether in the context of the logic.
Time Units
As you can imagine contracts might want to work with different notions of time for various types of logic that they want to encode. Solidity
supports different suffixes that represent time, and these can be applied to literal numbers and these suffixes are: seconds
, minutes
, hours
, days
and weeks
.
The base unit for time is seconds
, so literally when 1 is used it is the same as representing 1 seconds
. The suffixes cannot be directly applied onto variables, so if you want to apply time units to certain variables, then one needs to multiply that variable with that time unit.
So as an example shown, if we have a daysafter
variable and we wanted to represent the number of days then we have to proceed like follows
That is the only way how Solidity allows one to use these units with variables.
Last updated