---
title: "什么是 WEI？"
description: "Wei 是 ether 的最小单位，ether 是 Ethereum 上用于交易的货币。"
---

## 什么是 WEI？

[Wei](https://www.alchemy.com/docs/web3-glossary) 是以太币的最小单位，以太币是用于在 Ethereum 区块链网络上执行交易操作的货币，其中 10^18，即 1,000,000,000,000,000,000 wei 等于 1 个以太币。

Wei 得名于 Wei Dai，他毕业于华盛顿大学计算机科学专业，曾在微软的密码学研究部门工作。Wei Dai 是 20 世纪 90 年代密码朋克运动的一员，该运动的成员为 2010 年代加密货币奠定了理论基础。由于他提出的 b-money 概念——这一构想发表于一份自行出版的原始加密宣言，为智能合约奠定了基础——以太币的最小单位便以他的名字命名。

由于所有基于 Ethereum 网络构建的服务和应用都需要计算能力，而计算能力并非免费获取，因此需要某种形式的支付来获取这种计算能力。

尽管以太币是该网络的货币，但它常被比喻为 Ethereum 网络的“燃料”。其作为加密燃料的效用价值通常被称为“gas”。

Gas 是所有网络请求的核心组成部分，请求发送方需要为所消耗的计算资源付费。总体 gas 成本根据请求的数据量与复杂度，乘以当前的 gas 价格计算得出。

<EmbeddedTable
  table={{
    columns: [
      { key: "1", width: 200, title: "Unit", dataType: "object" },
      { key: "2", width: 200, title: "Alternative Name", dataType: "object" },
      {
        key: "1703851661082",
        width: 180,
        title: "Wei Value",
        dataType: "object",
      },
      {
        key: "1703851670504",
        width: 180,
        title: "Gwei Value",
        dataType: "object",
      },
      {
        key: "1703851679972",
        width: 180,
        title: "Ether Value",
        dataType: "object",
      },
    ],
    data: [
      {
        "1": { title: "<p>Wei</p>", tooltip: "", icon: "" },
        "2": { title: "<p>Wei</p>", tooltip: "", icon: "" },
        id: 0,
        "1703851661082": { title: "<p>1 Wei</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>10^-9 Gwei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>10^-18 ETH</p>", tooltip: "", icon: "" },
      },
      {
        "1": { title: "<p>Kwei</p>", tooltip: "", icon: "" },
        "2": { title: "Babbage", tooltip: "", icon: "" },
        id: 1,
        "1703851661082": { title: "<p>10^3 Wei</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>10^-6 Gwei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>10^-15 ETH</p>", tooltip: "", icon: "" },
      },
      {
        "1": { title: "<p>Mwei</p>", tooltip: "", icon: "" },
        "2": { title: "<p>Lovelace</p>", tooltip: "", icon: "" },
        id: 2,
        "1703851661082": { title: "<p>10^6 Wei</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>10^-3 Gwei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>10^-12 ETH</p>", tooltip: "", icon: "" },
      },
      {
        "1": { title: "<p>Gwei</p>", tooltip: "", icon: "" },
        "2": { title: "<p>Shannon</p>", tooltip: "", icon: "" },
        id: 3,
        "1703851661082": { title: "<p>10^9 Wei</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>1 Gwei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>10^-9 ETH</p>", tooltip: "", icon: "" },
      },
      {
        "1": { title: "<p>Twei</p>", tooltip: "", icon: "" },
        "2": { title: "<p>Szabo</p>", tooltip: "", icon: "" },
        id: 4,
        "1703851661082": { title: "<p>10^12 Wei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>10^-6 ETH</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>10^3 Gwei</p>", tooltip: "", icon: "" },
      },
      {
        "1": { title: "<p>Pwei</p>", tooltip: "", icon: "" },
        "2": { title: "<p>Finney</p>", tooltip: "", icon: "" },
        id: 5,
        "1703851661082": { title: "<p>10^15 Wei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>10^-3 ETH</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>10^6 Gwei</p>", tooltip: "", icon: "" },
      },
      {
        "1": { title: "<p>Ether</p>", tooltip: "", icon: "" },
        "2": { title: "", tooltip: "", icon: "" },
        id: 6,
        "1703851661082": { title: "<p>10^18 Wei</p>", tooltip: "", icon: "" },
        "1703851679972": { title: "<p>1 ETH</p>", tooltip: "", icon: "" },
        "1703851670504": { title: "<p>10^9 Gwei</p>", tooltip: "", icon: "" },
      },
    ],
  }}
/>

### wei 有哪些计量单位？

美元最小只能划分为 100 等份，即分（penny），而加密货币则可以划分为小得多的原子单位。

这些单位确保能够恰当地表示以太币的数值——某些数值看似很小，但换算成美元或其他主要货币后其实数额较大。

因此，以太币存在多个不同层级的 wei。每个子单位表示不同的数量级，如上所述，它们也各有别名。

## 什么是 gwei？

Gwei 是 wei 与 giga（十亿的单位前缀）两个词的结合，是 Ethereum 区块链网络所使用的数字货币以太币的另一个计量单位。1 gwei 等于 10 亿 wei，[1 个以太币等于 10^9，即 1,000,000,000 gwei](https://www.alchemy.com/docs/web3-glossary)。Gwei 也被称为纳以太（nanoether）或 Shannon，这一名称来源于 **Claude Shannon**，他是一位著名的美国数学家和密码学家，被誉为信息论之父。

由于 gas 价格的运作与表示方式，gwei 是以太币中最常用的计量单位。由于 gas 是在 Ethereum 网络上执行合约或其他交易所需支付的价格值，因此需要用 gwei 来支付计算能力的费用。

在 Ethereum 区块链网络上，标准交易费用为 21,000 gwei。通常，交易费用会随着交易的底层复杂度成比例上升。

2021 年 7 月，作为 London 硬分叉的一部分，[Ethereum Investment Proposal (EIP) 1559](/overviews/what-is-eip-1559) 改变了 Ethereum 区块链网络的手续费机制。此前，开发者和整个生态系统不得不依赖价格拍卖机制，即出价最高者的交易会被优先处理。

随着 EIP-1559 的引入，系统会为下一区块中要打包的交易设定一个明确的基础费用（base fee）。不过，用户仍可以添加“小费”或“优先费”，以确保矿工优先处理自己的交易。希望深入了解[如何使用 EIP-1559 发送交易](https://www.alchemy.com/docs/how-to-send-transactions-on-ethereum)的开发者，可以阅读 Alchemy 的 EIP-1559 文档。

计算交易费用的方法是使用以下公式：

**Gas Units (Limit) x (Base Fee + Tip)**

总体而言，基于区块需求的费用机制对当今用户而言更加直接和透明。此外，开发者还可以通过 Alchemy 使用 [EIP-1559 方法构建 gas 费用估算器](https://www.alchemy.com/docs/how-to-send-transactions-on-ethereum)。

## 如何将 wei 转换为 gwei

将 wei 转换为 gwei 的方法是将 wei 总量除以 10 亿，共分三步。

开发者可以使用换算计算器来理解 wei 与 gwei 之间的关系，也可以按照以下简单步骤操作：

1. 统计 wei 的数量
1. 使用基础除数 10^9，即 10 亿
1. 将 wei 数量除以基础除数

这样即可得到对应的 gwei 总量。

例如，420,069,000,000 wei / 1,000,000,000 = 420.069 gwei。

若要计算以美元计的价格，将 gwei 总量乘以当前 1 个以太币的价格，再除以 1,000,000,000（10^9）。

例如，若以太币价格为 1,000 美元，则 420.069 gwei 等于 0.000420069 美元，约为 1 美分的 1/25。

## 如何将 wei 转换为 ETH

与将 wei 转换为 gwei 类似，用户可以使用换算工具，或按照以下三步进行换算：

1. 统计 wei 的总数量
1. 使用基础除数 10^18，即 1 quintillion（百万的三次方）
1. 将 wei 数量除以基础除数

这样即可得到 ETH 的总量。

例如，100 万亿 wei / 10^18 = 0.0001 ETH。

若要计算以美元计的价格，将 ETH 数量乘以当前 ETH 的价格。
例如，当 1 ETH 价格为 1,000 美元时，0.0001 ETH 等于 0.10 美元。

## 如何在代码中将 wei 转换为 ETH

以下是使用 Alchemy SDK 将 ETH 转换为 gwei 的方法：

1. 安装 alchemy SDK
1. 输入或获取要转换的数量
1. 调用 formatEther 方法转换为 ETH

下面的示例演示了如何获取 vitalik.eth 的以太币余额（以 gwei 返回），并将其以 ETH 的形式打印出来：
