Solidity 学习笔记
通过学习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 |
etherSolidity中,单位之间的换算是在数字后边加上wei,gwei 或ether 来实现的Solidity中,后面没有单位,缺省为weiSolidity 0.7.0版本开始,finney 和 szabo 被移除了gwei 在Solidity 0.6.11版本中添加,因此在0.6.11之前的版本中不可用该例子是测试了以太币的单位换算
// 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;
1 wei 等于 1,若没填写单位,默认是以wei为单位uint public oneEther = 1 ether;
bool public isOneEther = 1 ether == 1e18;
ether 等于 $10^{18}$ weiuint public oneGwei = 1 gwei;
bool public isOneGwei = 1 gwei == 1e9;
gwei 等于 $10^9$ wei