# 如何为 NFT 定价

您刚刚创建了一个 NFT，并想将其出售给您的 NFT 爱好者。为此，我们必须为 NFT 定价，定价的主要方式有两种：

1. 在智能合约中（本指南）
2. 在 NFT 市场或平台上列出 NFT（更流行的方法）<br>

### 在合约中设置 NFT 价格

**铸币时需要费用**

> 注意：以下部分不是交钥匙解决方案。在NFT 创建教程的第 10 步中，我们需要更改 Solidity 以接受铸造付款，这意味着任何 frontendweb3 / ethers.jslogic 指示铸造都需要包含 themsg.value 参数以允许 ETH 的转移。 &#x20;

这种费用模式是完全去中心化的，因为它发生在合同中，并将费用机制融入到铸币过程本身中。要实施铸造价格，您需要更改您的智能合约以包含此行为。作为一个高层次的总结，NFT 铸造价格可以通过使铸造功能可支付并要求用户在触发 NFT 转移给买方之前支付特定数量的 ETH 来制定。

以下是此类铸币过程的示例代码：

```js
function mintToken(address to, uint256 tokenId, string uri) public virtual payable {

  require(msg.value >= 10, "Not enough ETH sent; check price!");

  mint(to, tokenId);
  _setTokenURI(tokenId, uri);
}
```

**函数 mintToken(address to, uint256 tokenId, string uri) public virtual payable**

* 为了让用户支付 ETH 来铸造 NFT，我们需要将此功能公开和支付。可以在内部或通过消息调用公共函数，以允许任何人与该函数进行交互。（我们不希望这个函数只能由合约所有者调用，因为这会把潜在买家拒之门外！）

**require(msg.value >= 10, "发送的 ETH 不够；检查价格！");**

* 此 require 语句要求 payable 函数至少收到 10 wei，否则该函数将失败并恢复。msg.value 参数是与 mint 函数一起发送的数量的 ETH 值。**‍**

**薄荷（到，tokenId）；**

* 这会调用 OpenZepplin 的 ERC721 合约文件中包含的 mint 函数，并将选定的 NFT 实例化/转移给买方。

**\_setTokenURI(tokenId, uri);**

* 这会调用 OpenZepplin 的 ERC721 合约文件中包含的 \_setTokenURI 函数，并将 NFT URI 设置为特定端点。 &#x20;

‌在铸造合同中实施费用有许多不同的变体。上面列出的是最简单的协议之一，但许多协议也使用复杂得多的费用模式。

### 通过拍卖平台设定 NFT 价格

**在 OpenSea 或其他 NFT 拍卖平台上列出 NFT**

一种非编码替代方案是简单地在 OpenSea 或其他 NFT 拍卖网站上列出您新铸造的 NFT，这样您就可以为其定价。运行在 NFT 之上的 OpenSea 的 UI 层允许您定价、接受出价或使用其他更复杂的拍卖方法并为您处理所有逻辑。

[对于以太坊主网，请使用： https](https://opensea.io/) ://opensea.io/

对于测试网，请使用：[https ://testnets.opensea.io/](https://testnets.opensea.io/)

> **注意：** NFT 拍卖平台通常对上市和处理拍卖过程收费。与不同的平台保持同步，以找到有竞争力的价格并最大化您的 NFT 销售额。[Zora](https://zora.co/)和[SuperRare](https://superrare.com/)是两个替代平台，它们也提供与 OpenSea 类似的服务。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chengwf.com/build-your-first-nft/how-to-set-a-price-on-a-nft.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
