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 is the smallest value of ether.
Gwei is 1 billion wei
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!
📙 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