This is Solidity Tutorial series article 7th introduces the etheric units and time units, series with you to thoroughly understand the solidity language.
Write in front
Solidity is the Ethereum Smart Contract programming language, you should know about Ethereum and smart contracts before reading this article.
If you don't understand, it's recommended that you look at Ethereum first.
Subscribe to the Blockchain technology column to read more comprehensive analysis articles.
Monetary unit (ether Units)
A numeric constant (literal) follows a suffix wei, Finney,Szabo , or ether, which is the currency unit. Different units can be converted. The default unit that does not contain any suffixes is wei.
The different etheric unit conversion relationships are as follows:
- 1 ether = = 10^3 Finney = = Finney
- 1 ether = = 10^6 Szabo
- 1 ether = = 10^18 Wei
Episode: The Ethereum unit is actually the name of the cipher, and is the founder of Ethereum to commemorate their contribution in the field of digital money. They were:
Wei:wei Dai either David Cipher, published in B-money
Finney:hal Finney, work proof mechanism (POW) proposed
Szabo:nick Szabo, the creator of the smart contract for the Saab
We can use the code to verify a transformation relationship:
pragma solidity^0.4.16;Contract Testunit{ function TF() PublicPurereturns(BOOL){ if(1Ether== +Finney{ return true; } return false; } function TS() PublicPurereturns(BOOL){ if(1Ether== 1000000Szabo{ return true; } return false; } function TGW() PublicPurereturns(BOOL){ if(1Ether== 1000000000000000000Wei{ return true; } return false; }}
Time Unit (Units)
Time units: seconds, minutes, hours, days, weeks, years can be used as suffixes, and to convert each other, the rules are as follows:
- 1 = = 1 seconds (default is seconds)
- 1 minutes = = seconds
- 1 hours = = Minutes
- 1 days = = Hours
- 1 weeks = 7 days
- 1 years = 365 days
Using these units for date calculations requires special care, because not every year is 365 days, and not every day there are 24 hours, because there are leap seconds. Because the leap seconds cannot be predicted, it must be updated by the External prophecy (Oracle) to get an accurate calendar library.
These suffixes cannot be used for variables. If you want to explain the different units of the input variables, you can use the following method:
pragma solidity ^ 0.4.16 Contract Testtunit { function currtimeinseconds
() public pure returns (uint256) {
return
now } function f (UINT start uint Daysafter) public { if (now >= start + daysafter * 1 days) { //... } } }
Reference documents
In-depth blockchain-the system learns blockchain to create the best blockchain technology blog.
If you want to have a closer communication with me you can choose to join my knowledge planet (members of the planet can join the technology Exchange Group).
Smart Contract Language Solidity Tutorial Series 7-etheric units and time units