---
title: "在 Ethereum 上部署 NFT 项目要花多少钱？"
description: "长话短说，视情况而定……"
---

# 在 Ethereum 上部署 NFT 项目要花多少钱？

<ExternalVideo
  url="https://www.youtube.com/watch?v=dnYSdTAQylk&embeds_referring_euri=https%3A%2F%2Falchemy.com%2F&source_ve_path=Mjg2NTksOTY3MTQ&feature=emb_imp_woyt&ab_channel=Alchemy"
  provider="youtube"
  providerUid="dnYSdTAQylk"
/>

长话短说，这取决于具体情况。

<ImageBlock
  src="https://media.alchemy.com/1704715758-the-price-of-ether-has-skyrocketed-in-2021.png"
  alt="2021 年以太币价格飞涨……gas 费也是如此！"
  width={802}
  height={753}
  caption="2021 年以太币价格飞涨……gas 费也是如此！"
/>

以太币的价格在 2021 年飙升……gas 费用也随之飙升！

如果你第一次接触 [Web3 development](https://www.alchemy.com/overviews/how-to-learn-web3-development)，正在了解 [Solidity](https://soliditylang.org/) 编程语言、[Ethereum](https://ethereum.org/en/) 智能合约以及[制作 NFT](https://www.youtube.com/watch?v=ftMzXpToq9Q)……

1. 欢迎！你将经历一段不小的旅程……
1. 一定要弄清楚 gas 费用和交易费用的运作方式！

以前……部署[去中心化应用](https://www.alchemy.com/dapps/top/defi-dapps)的成本相对较低。

- 2017 年，[CryptoPunks](https://www.larvalabs.com/cryptopunks) NFT 项目的部署成本为 **7.56 美元**（[来源](https://etherscan.io/tx/0x0885b9e5184f497595e1ae2652d63dbdb2785de2e498af837d672f5765f28430)）
- 2020 年，Shiba Inu Token（$SHIB）的部署成本为 **60 美元**（[来源](https://etherscan.io/tx/0x0a4022e61c49c59b2538b78a6c7c9a0e4bb8c8fce2d1b4a725baef3c55fb7363)）

而今天——2021 年 11 月 30 日——部署同样的合约要付出高昂的代价 :(

- [CryptoPunks](https://www.larvalabs.com/cryptopunks) 将花费 **964 美元**
- $SHIB 将花费 **2,026 美元**

也就是说，按美元计算，如今在 Ethereum 上部署合约的成本，比几年前高出 30 到 120 倍。

<ImageBlock
  src="https://media.alchemy.com/1704715821-cryptopunks-is-one-of-the-earliest-and-most-successful-nft-projects-around.png"
  alt="CryptoPunks 是最早也是最成功的 NFT 项目之一。"
  width={1128}
  height={911}
  caption="CryptoPunks 是最早也是最成功的 NFT 项目之一。"
/>

那么问题来了……为什么会这样？

其实，有三个因素最终决定了你的部署成本：

1. 部署合约交易所消耗的 gas **单位数（UNITS）**
1. 基于当前流量和网络拥堵情况的每单位 gas **价格（PRICE）**
1. 基于市场行情的 Ether（ETH）**价值（VALUE）**

这三个因素通过一个非常简单的公式组合在一起：

**总成本** = **单位数** **价格** **价值**

我们先来看 [2017 年 CryptoPunks 合约的部署交易](https://etherscan.io/tx/0x0885b9e5184f497595e1ae2652d63dbdb2785de2e498af837d672f5765f28430)作为示例。根据 [Etherscan](https://etherscan.io/) 上的交易信息：

1. gas **单位数** = 2,142,276 gas
1. 每单位 gas **价格** = 0.000000011 ETH（即 11 gwei）
1. ETH **价值** = 320.97 美元/ETH

总成本 = 2,142,276 0.000000011 320.97

**总成本 = 7.56 美元**

那么，如果我们今天，也就是 2021 年，尝试部署同样的 CryptoPunks 合约，会有什么变化？

- **单位数**保持不变——gas 单位数取决于智能合约中包含的逻辑，而这份合约与四年前完全相同。
- **价格**上升了——Ethereum 已经成为一个交易非常活跃的区块链，流量越大，由于 gas 竞价机制，单位 gas 以 ETH 计价的成本就越高。竞价机制指的是用户不断提高交易中附带的 gas 费用，以激励矿工优先打包自己的交易。
- ETH 的**价值**也上升了——随着时间推移，更多投资者和更多关注意味着对这种加密货币的需求增加。

如今每单位 gas 的平均**价格**大约在 0.0000001 ETH ~ 0.00000015 ETH（100~150 gwei）之间，而 ETH 的平均**价值**大约在 4,000 ~ 4,500 美元之间。

那么今天部署 CryptoPunks 合约的计算会是怎样的？

1. gas **单位数** = 2,142,276 gas
1. 每单位 gas **价格** = 0.0000001 ETH（即 100 gwei）
1. ETH **价值** = 4,500 美元/ETH

**总成本** = 2,142,276 0.0000001 4,500 = **964 美元**

自己动手试一试！在 [Etherscan](https://www.alchemy.com/dapps/etherscan) 上查一个你喜欢的 NFT 合约，找出交易费用的三个组成部分，验证最终成本。你今天看到的是什么样的价格？把你的例子发到 Twitter [@thatguyintech](https://twitter.com/thatguyintech)，我很乐意转发 :)

现在你可能会想，“既然这么贵，为什么大家还在 Ethereum 上构建？”

这是个好问题。原因主要有三个：

1. **去中心化**。Ethereum 是目前去中心化程度最高的智能合约平台。根据 [ethernodes.org](https://ethernodes.org/) 的数据，运行该网络的节点超过 3000 个。其他智能合约平台的节点或验证者数量要少得多。网络越去中心化，就越难被审查、控制、操纵或关闭。对于严肃的金融应用而言，这些保障通常是必需的。
1. **开发者生态**。它拥有最大的开发者生态和最成熟的工具链。根据 Electric Capital 的数据，[Ethereum 每月活跃开发者超过 2400 人，且仍在增长](https://medium.com/electric-capital/electric-capital-developer-report-2020-9417165c6444)。Ethereum 是最古老的智能合约平台，在构建可用的应用和可组合的工具方面享有最强的网络效应。‍
1. **市场**。Ethereum 拥有最大的应用市场（最多的用户和资金）。目前最大、使用最广泛的 DeFi 协议和 NFT 交易市场都建立在 Ethereum 上。

不过，即便有这些优势，也不意味着 Ethereum 一定是你的项目的最佳选择。也许你只是在探索和学习，部署到 [Ethereum mainnet](https://www.alchemy.com/rpc/ethereum) 的成本完全没有意义。又或者你的用例非常特定，比起去中心化保障更看重速度和效率。无论原因是什么，你都有很多理由去探索其他选择。这里介绍几个可以入手的替代方案……

如果你想留在 [Ethereum ecosystem](https://www.alchemy.com/dapps/ecosystem/ethereum) 内，可以看看**侧链（sidechain）**和 **layer 2**（L2）：

- [Polygon](https://polygon.technology/)
- [Immutable X](https://www.immutable.com/)
- [Optimism](https://www.optimism.io/)
- [Arbitrum](https://offchainlabs.com/)
- [ZKSync](https://zksync.io/)
- [StarkNet](https://starkware.co/)

<ImageBlock
  src="https://media.alchemy.com/1704715961-polygon-approach-to-scaling-ethereum.png"
  alt="Polygon's approach to scaling Ethereum - https://polygon.technology"
  width={430}
  height={430}
  caption="Polygon's approach to scaling Ethereum - https://polygon.technology"
/>

使用侧链或 Ethereum layer 2 方案的好处在于，你可以使用相似的工具链，而记录交易和保护 DApp 安全的底层机制保持不变。你还能享受到大幅降低的交易成本和更快的速度。代价是目前用户体验和开发者体验可能都还不够完善。

如果你想走得更远一些，探索采用不同编程语言和不同系统架构的区块链，可以考虑这些其他的 **layer 1**（L1）：

- [Flow](https://www.onflow.org/)
- [Solana](https://solana.com/)
- [Avalanche](https://www.avax.network/)
- [Tezos](https://tezos.com/)
- [Polkadot](https://polkadot.network/)

最后，如果你担心部署成本，但仍然想部署到 Ethereum mainnet 上，可以尝试优化你的 solidity 代码，减少不必要的逻辑。gas 费用的目的是为了向矿工支付运行你程序逻辑的费用。逻辑越简单，部署和运行合约的成本就越低。

这里有[一篇很棒的文章，讲的是如何优化 Ethereum NFT 智能合约以降低 gas 消耗](https://medium.com/@kaymonft/optimizing-nft-smart-contracts-to-reduce-gas-usage-7f4e819eb49d)。

<EmbeddedTable
  table={{
    columns: [
      { key: "1", width: 200, title: "ERC721Enumerable", dataType: "object" },
      { key: "2", width: 200, title: "Gas Amount", dataType: "object" },
      { key: "3", width: 200, title: "Total Cost ETH", dataType: "object" },
      { key: "4", width: 200, title: "Total Cost USD", dataType: "object" },
    ],
    data: [
      {
        "1": { title: "<p><strong>Deployment Cost</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>1,775,269</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.25208198</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$1,076.92</p>", tooltip: "", icon: "" },
        id: 0,
      },
      {
        "1": { title: "<p><strong>Mint 1 (Wallet 1)</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>102,474</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.01455130</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$62.16</p>", tooltip: "", icon: "" },
        id: 1,
      },
      {
        "1": { title: "<p><strong>Mint 2 (Wallet 1)</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>147,874</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.02099810</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$89.70</p>", tooltip: "", icon: "" },
        id: 2,
      },
      {
        "1": { title: "<p><strong>Mint 3 (Wallet 1)</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>147,874</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.02099810</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$89.70</p>", tooltip: "", icon: "" },
        id: 3,
      },
      {
        "1": { title: "<p><strong>Mint 4 (Wallet 2)</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>145,074</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.02060050</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$88.01</p>", tooltip: "", icon: "" },
        id: 4,
      },
      {
        "1": { title: "<p><strong>Mint 5 (Wallet 2)</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>147,874</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.02099810</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$89.70</p>", tooltip: "", icon: "" },
        id: 5,
      },
      {
        "1": { title: "<p><strong>Mint 6 (Wallet 2)</strong></p>", tooltip: "", icon: "" },
        "2": { title: "<p>147,874</p>", tooltip: "", icon: "" },
        "3": { title: "<p>0.02099810</p>", tooltip: "", icon: "" },
        "4": { title: "<p>$89.70</p>", tooltip: "", icon: "" },
        id: 6,
      },
    ],
  }}
/>

‍如果这篇说明对你有帮助，欢迎发推给我们 [@Alchemy](https://x.com/Alchemy)！我们很想看看你在构建什么，并为你的项目助一把力 :)

<ImageBlock
  src="https://media.alchemy.com/1704716189-introducing-gas-price-notification.png"
  alt="介绍 Alchemy gas 价格通知功能的横幅"
  width={1106}
  height={796}
  caption="推出 gas 价格通知功能"
/>
