New to blockchain software development? Read my beginners guide here

How to use ether units in Solidity

Created on August 2022 β€’ Tags: ethereumsolidityguides

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!

See all posts (70+ more)

See all posts (70+ more)

Was this post helpful? πŸ“§

If you liked this content and want to receive emails about future posts like this, enter your email. I'll never spam you.

Or follow me on @CryptoGuide_Dev on twitter

By using this site, you agree that you have read and understand its Privacy Policy and Terms of Use.
Use any information on this site at your own risk, I take no responsibility for the accuracy of safety of the information on this site.