| Solidity Time Unit | Number of seconds |
|---|---|
seconds |
1 |
minutes |
60 |
hours |
3,600 |
days |
86,400 |
weeks |
604,800 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDC-License-Identifier: Apache-2.0 | |
| pragma solidity ^0.8.10; | |
| contract TimeUnits { | |
| function Seconds() public pure returns (uint256) { | |
| // 1 | |
| return 1 seconds; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract EtherUnits { | |
| function assignEtherUnits() public { | |
| uint256 gasWithExtraFee = 2 gwei + 5_000 wei; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract EtherUnits { | |
| function example() public { | |
| uint256 a = 20; | |
| // test = 5,000,000,000,000,000,020 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract StakeHolders { | |
| uint256 immutable numberOfStakeholders; | |
| constructor(uint256 numberOfStakeholders_) { | |
| numberOfStakeholders = numberOfStakeholders_; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract EtherUnits { | |
| function notWorking() public { | |
| uint256 total; | |
| // TypeError: Hexadecimal numbers cannot be used with unit denominations. | |
| // You can use an expression of the form "0x1234 * 1 day" instead. |
| Unit | ➕ Number of decimals 0s |
➖ Number of fractional 0s |
1 Ether = |
|---|---|---|---|
| wei | 18 | 1,000,000,000,000,000,000 Wei | |
| kwei | 15 | 1,000,000,000,000,000 Kwei | |
| mwei | 12 | 1,000,000,000,000 Mwei | |
| gwei | 9 | 1,000,000,000 Gwei | |
| ether | ... | ... | ... |
| kether | 3 decimals | 0.001 Kether | |
| mether | 6 decimals | 0.000001 Mether | |
| gether | 9 decimals | 0.000000001 Gether |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract EtherUnits { | |
| function minimumTypes() public { | |
| // minimum `uintN` type for wei = any | |
| // OK | |
| uint8 a = 1 wei; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity >=0.7.0 <0.9.0; | |
| contract Ownable { | |
| address private owner; | |
| // event for EVM logging | |
| event OwnerSet(address indexed oldOwner, address indexed newOwner); | |
| // modifier to check if caller is owner | |
| modifier isOwner() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: GPL-3.0 | |
| pragma solidity ^0.8.0; | |
| contract ContractTemplate { | |
| // some logic here... | |
| } | |
| abstract contract MyContract { | |
| // This will not compile and throw the error |