---
title: "什麼是 WEI？"
description: "Wei 是 ether 的最小單位，ether 是 Ethereum 上交易使用的貨幣。"
---

## 什麼是 WEI？

[Wei](https://www.alchemy.com/docs/web3-glossary) 是 ether 的最小單位，ether 是用來在 Ethereum 區塊鏈網路上執行交易操作的貨幣，10^18（即 1,000,000,000,000,000,000）wei 等於 1 ether。

Wei 的命名來自 Wei Dai，他是華盛頓大學的資訊科學畢業生，曾任職於微軟的密碼學研究部門。Wei Dai 是 1990 年代密碼龐克運動（cypherpunk movement）的一員，該運動的成員為 2010 年代的加密貨幣奠定了理論基礎。因為他在自行發表的原型加密宣言中提出了 b-money 的構想（這份宣言為智能合約打下了基礎），ether 的最小單位便以他的名字命名。

由於建構在 Ethereum 網路上的所有服務與應用程式都需要運算能力，而運算能力並非免費取得，因此需要某種形式的支付方式來取得運算能力。

雖然 ether 是這個網路的貨幣，但它常被比喻為 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），但加密貨幣可以分割成小得多的最小單位。

這些單位確保 ether 能有適當的計價方式，因為 ether 的數值看起來可能相對很小，但換算成美元或其他主要貨幣時其實金額不小。

因此，ether 具有多個不同層級的 wei。每個子單位代表數量，但如上所述，各有其他名稱。

## 什麼是 gwei？

Gwei 是 wei 與 giga（十億的單位字首）組合而成的字，是 ether 的另一種計價單位，ether 是 Ethereum 區塊鏈網路使用的數位貨幣。1 gwei 等於 10 億 wei，[1 ether 等於 10^9（即 1,000,000,000）gwei](https://www.alchemy.com/docs/web3-glossary)。Gwei 也稱為 nanoether 或 Shannon，這個名稱來自 **Claude Shannon**，他是美國著名的數學家與密碼學家，被視為資訊理論之父。

由於 gas 價格的運作方式與表示方式，Gwei 是最常用的 ether 單位。由於 gas 是在 Ethereum 網路上執行合約或其他形式交易所需的定價值，因此需要用 gwei 來支付運算能力。

在 Ethereum 區塊鏈網路上，標準交易費用為 21,000 gwei。一般而言，交易費用會隨著交易本身的複雜度成比例上升。

2021 年 7 月，作為 London 硬分叉（Hard Fork）的一部分，[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 ether 的價格再除以 1,000,000,000（10^9）。

例如，若 Ether 價格為 $1,000，則 420.069 gwei 等於 $0.000420069，約為一分錢的 1/25。

## 如何將 wei 換算成 ETH

與將 Wei 換算成 Gwei 類似，使用者可以使用 wei 換算器，或依照以下 3 步驟流程操作：

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 的 ether 餘額（以 gwei 回傳），並以 ETH 的形式印出：
