avatarClaspintech

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1063

Abstract

in the following example Etherunits contract is written and executed in Remix IDE. The programs has two functions isOneEther and isOneWei. The isOneWei will return true when 1 wei is equal to 1 literal. And in the same way isOneEther will return true when 1 ether is equal to 1e18 (1 x 1018). The program also display the value of 1 wei and 1 ether.</p><figure id="02ea"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*rle4qZ9HTw5vjXQIrFQwxA.png"><figcaption>EtherUnit contract is executed and isOneEther method returns true value.</figcaption></figure><figure id="1ee3"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*rfpfSNTz5bF3Vak85hLDNw.png"><figcaption>isOneWei is returns true. oneEther and oneWei value are also displayed.</figcaption></figure><p id="4076">You can find the unit details in any of the transactions listed in etherscan.io</p><figure id="2db0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*omLHjYFuE-cnxZ1ejW3hOg.png"><figcaption>Transaction fee is displayed Ether</figcaption></figur

Options

e><h1 id="01b8">Time Units</h1><p id="9ae2">Similar to currency unit the Solidity has time unit to specify seconds, minutes, hours, weeks and days as suffixes. The lower units second. The suffix <b><i>years </i></b>is removed in version 0.5.0 due to difficulty of calculation in leap seconds.</p><p id="cc6b">In code, it can be referred as,</p><p id="7d1a"><b>uint a = 3 minutes // 180 or 360</b></p><p id="61c6"><b>uint b = 2 hours; // 7200 or 26060</b></p><p id="3213"><b>uint c = 3 weeks // 1814400 or 372460*60</b></p><p id="d826">it is also possible to use math operations like + and — symbols with any time unit.</p><p id="6af8"><b>uint date = 1658997083;</b></p><p id="fbf6"><b>uint laterDate = date + 1 days;</b></p><p id="af71"><b>uint beforeDate = date — 3 days;</b></p><p id="d2cf"><b>uint prevWeek = date — 1 weeks;</b></p><p id="76c4">We hope that this helps for better understanding of ether and time unit of solidity. Enjoy reading :) :) :)</p><p id="552e" type="7">New to trading? Try crypto trading bots or copy trading</p></article></body>

Units in Solidity

Almost in all the programming languages we must be heard of local, static and global variables. Similar way Solidity also has units and globally available variables. The units are divided into Ether and Time units. Ether is important and used to transfer between accounts and paying transaction fees.

Ether Units:

We need currency to make transactions for good and services, similarly Ether is used to pay for the computational transactions that’s currency of Ethereum virtual machine. It is referred as denomination.

Ether Units

In Ether units, the smallest unit is wei and the largest is ether and they can be converted like dollars and cents. The literal can be with the suffix like wei, finney and szabo. The currency without the postfix is by default taken as smaller unit, Wei.

Here in the following example Etherunits contract is written and executed in Remix IDE. The programs has two functions isOneEther and isOneWei. The isOneWei will return true when 1 wei is equal to 1 literal. And in the same way isOneEther will return true when 1 ether is equal to 1e18 (1 x 1018). The program also display the value of 1 wei and 1 ether.

EtherUnit contract is executed and isOneEther method returns true value.
isOneWei is returns true. oneEther and oneWei value are also displayed.

You can find the unit details in any of the transactions listed in etherscan.io

Transaction fee is displayed Ether

Time Units

Similar to currency unit the Solidity has time unit to specify seconds, minutes, hours, weeks and days as suffixes. The lower units second. The suffix years is removed in version 0.5.0 due to difficulty of calculation in leap seconds.

In code, it can be referred as,

uint a = 3 minutes // 180 or 3*60

uint b = 2 hours; // 7200 or 2*60*60

uint c = 3 weeks // 1814400 or 3*7*24*60*60

it is also possible to use math operations like + and — symbols with any time unit.

uint date = 1658997083;

uint laterDate = date + 1 days;

uint beforeDate = date — 3 days;

uint prevWeek = date — 1 weeks;

We hope that this helps for better understanding of ether and time unit of solidity. Enjoy reading :) :) :)

New to trading? Try crypto trading bots or copy trading

Blockchain Technology
Blockchain
Blockchain Development
Solidity
Ethereum
Recommended from ReadMedium