Solidity中常用的单位Ether和Wei

459 阅读1分钟

以太坊上的交易使用以太(ether)来支付gas费。

就像一美金等于100美分,1 ether 等于10^18wei

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

contract EtherUnits {
    uint public oneWei = 1 wei;
    // 1 wei 就用数字 1 来表示
    bool public isOneWei = 1 wei == 1;

    uint public oneEther = 1 ether;
    // 1 ether 等于 10^18 wei
    bool public isOneEther = 1 ether == 1e18;
}