Member-only story
Solidity Tutorial: All About Ether Units
Using different currency units available in Solidity when writing smart contracts
In this article, we will learn the basics of Ether Units in Solidity. We will look at how to specify ether denominations like wei
, gwei
and ether
and the different options available for declaring values suffixed with one of these Ether denominations.
Table of Contents
Introduction to Ethers Currency Units
Ethers Units Available in Solidity
Allowed Values for Ether Units
Expressions With Ethers Units
Specifying Amounts With Native Token Transfers Between Contracts
Introduction to Ethers Currency Units
Transactions in Ethereum are paid with Ether.
Ether units represent value, such as the amount of money transferred between accounts or the transaction cost.
Like many other cryptocurrencies, ether can be divided into smaller units of value. Similar to how one dollar is equal to 100 cents, one ether
is equal to 10¹⁸ wei
.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract EtherUnits {
uint public oneWei = 1 wei;
// 1 wei is equal to 1
bool public isOneWei = 1 wei == 1;
uint public oneEther = 1 ether;
// 1 ether is equal to 10^18…