Solidity-Learning

Solidity 学习笔记

View the Project on GitHub XdpCs/Solidity-Learning

007-以太币单位

背景

通过学习Solidity,然后输出文章检验自己的学习成果Github仓库

欢迎大家关注我的X

基础知识

单位 Wei Wei值
Wei 1 1 Wei
Kwei (babbage) 1,000 1e3 Wei
Mwei (lovelace) 1,000,000 1e6 Wei
Gwei (shannon) 1,000,000,000 1e9 Wei
Microether (szabo) 1,000,000,000,000 1e12 Wei
Milliether (finney) 1,000,000,000,000,000 1e15 Wei
Ether 1,000,000,000,000,000,000 1e18 Wei

例子

例子

该例子是测试了以太币的单位换算

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract EtherUnits {
    uint public oneWei = 1 wei;
    bool public isOneWei = 1 wei == 1;

    uint public oneEther = 1 ether;
    bool public isOneEther = 1 ether == 1e18;

    uint public oneGwei = 1 gwei;
    bool public isOneGwei = 1 gwei == 1e9;
}

程序解析

uint public oneWei = 1 wei;
bool public isOneWei = 1 wei == 1;
uint public oneEther = 1 ether;
bool public isOneEther = 1 ether == 1e18;
uint public oneGwei = 1 gwei;
bool public isOneGwei = 1 gwei == 1e9;

链接