DEV Community

Cover image for Day 15 - Units
Vedant Chainani
Vedant Chainani

Posted on • Edited on

Day 15 - Units

GitHub logo envoy1084 / 30-Days-of-Solidity

30 Days of Solidity step-by-step guide to learn Smart Contract Development.

Solidity

WARNING: This repository is currently undergoing updates and revisions to incorporate the latest information and advancements in Solidity programming. Please be advised that the content may not be up-to-date or accurate during this time. We expect the updates to be completed within the next 30 days, and appreciate your patience during this process. Thank you for your understanding.

Contents

This is Day 15 of 30 in Solidity Series
Today I Learned About Units in Solidity.

In solidity we can use wei, gwei or ether as a suffix to a literal to be used to convert various ether based denominations. Lowest unit is wei and 1e12 represents 1 x 10^12.

Similar to currency, Solidity has time units where lowest unit is second and we can use seconds, minutes, hours, days and weeks as suffix to denote time.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

contract MyUnits {
    // 1 wei == 1
    // 1 gwei == 1e9
    // 1 ether == 1e18
    uint256 costOfNFT = 12.5 ether;
    uint256 gasLimit = 3000 wei;

    //1 == 1 seconds
    //1 minutes == 60 seconds
    //1 hours == 60 minutes
    //1 days == 24 hours
    //1 weeks == 7 days

    uint256 durationOfMint = 7 days;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)