How to use ether units in Solidity
A guide to using units of ether in Solidity
Table of Contents for How to use ether units in Solidity
As well as being able to use dates/times like 2 hours
(see my post here about using dates/times in Solidity), you can also use the various ether keywords for values of eth.
wei
Wei is the smallest value of ether.
gwei
Gwei is 1 billion wei
ether
1 eth = 1,000,000,000,000,000,000 wei (10^18).
Using these eth values
You can use these and they return the number value they represent. e.g.
uint costToDoSomething = 5 wei; // = 5
uint somethingElse = 10 gwei; // 10 billion
uint amountOfEth = 0.5 ether; // (10^18)/5
Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!
Previous post
π Solidity Auditing online quiz
Learn how to audit smart contracts by looking at some example code and trying to find the bugs
β½ Solidity Gas Optimizations Guide
How to optimize and reduce gas usage in your smart contracts in Solidity
π§ͺ Guide to testing with Foundry
Guide to adding testing for your Solidity contracts, using the Foundry and Forge tools
π Guide to UTXO
UTXO and the UTXO set (used by blockchains such as Bitcoin) explained
π Solidity Assembly Guide
Introduction guide to using assembly in your Solidity smart contracts
π¦ Ethereum EOF format explained
Information explaining what the upcoming Ethereum EOF format is all about