交易是用以太币支付的。 类似于 1 美元等于 100 美分,1 以太币等于 10的18次方 wei。

Transactions are paid with

ether
.

Similar to how one dollar is equal to 100 cent, one

ether
is equal to 1018
wei
.

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

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 wei
    bool public isOneEther = 1 ether == 1e18;
}

Gas:你需要为一笔交易支付多少以太币? 你支付的 gas 花费 * gas price 的以太币数量,其中 气体是计算单位 消耗的气体是交易中使用的气体总量 汽油价格是您愿意为每种汽油支付多少以太币 具有较高gas价格的交易具有更高的优先级被包含在一个块中。

  • gas
    is a unit of computation
  • gas spent
    is the total amount of
    gas
    used in a transaction
  • gas price
    is how much
    ether
    you are willing to pay per
    gas
  • gas limit
    (max amount of gas you're willing to use for your transaction, set by you)
  • block gas limit
    (max amount of gas allowed in a block, set by the network)

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

contract Gas {
    uint public i = 0;

    // Using up all of the gas that you send causes your transaction to fail.
    // State changes are undone.
    // Gas spent are not refunded.
    function forever() public {
        // Here we run a loop until all of the gas are spent
        // and the transaction fails
        while (true) {
            i += 1;
        }
    }
}