> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/mei-ti/display-a-certified-nft.md). Agents can also search and read this documentation through its [MCP server](https://docs.decentraland.org/~gitbook/mcp).

# 显示已认证的 NFT

了解如何在你的场景中显示你拥有的已认证 NFT

你可以在自己的 Decentraland 场景中显示自己拥有的 2D NFT（非同质化代币）。

NFT 的图像和其他数据会根据代币的合约和 ID 从 API 获取。任何受 [OpenSea](https://opensea.io/) 支持的 NFT，也可以显示在 Decentraland 的 NFT 相框中。

{% hint style="info" %}
**💡 提示**：在 [Creator Hub 中的场景编辑器](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/ru-men/about-editor.md)里，你可以使用 **NFT** [智能物品](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md) ，无需编写代码即可实现此功能。
{% endhint %}

相框会根据 NFT 图像的尺寸进行调整。如果图像尺寸为 512 X 512 像素，相框将保持原始大小。如果图像尺寸不同，相框将调整大小并拉伸以匹配图像尺寸。

{% hint style="info" %}
**💡 提示**：如果你想要拉伸图像，或调整默认生成的图像尺寸，可以修改实体的 `scale` 属性，该属性位于实体的 `Transform` 组件中。
{% endhint %}

## 添加 NFT

向实体添加 `NftShape` 组件，即可在场景中显示 2D 代币。

```ts
const nft = engine.addEntity()

Transform.create(nft, {
	position: Vector3.create(8, 1, 8),
})

NftShape.create(nft, {
	urn: 'urn:decentraland:ethereum:erc721:0x06012c8cf97bead5deae237070f9587f8e7a266d:558536',
})
```

NftShape `NftShape` 组件必须通过一个包含以下内容的参数进行实例化：

* `urn` 字段。此字段接受一个字符串，其格式应如下：

`urn:decentraland:<CHAIN>:<CONTRACT_STANDARD>:<CONTRACT_ADDRESS>:<TOKEN_ID>`

此字符串包含：

* 代币所在的 *网络* 。请参阅下方支持的值列表。
* 代币所基于的 *合约标准* ，例如 `erc721`
* 代币的 *合约* （例如 CryptoKitties 合约）
* 要显示的特定代币 *ID* urn:decentraland:ethereum:erc721:0x06012c8cf97BEaD5deAe237070F9587f8E7A266d:558536

例如：

`urn:decentraland:ethereum:erc721:0x06012c8cf97BEaD5deAe237070F9587f8E7A266d:558536`

上面的示例会获取合约地址为 `0x06012c8cf97BEaD5deAe237070F9587f8E7A266d`的 NFT，以及其特定标识符 `558536`。对应的资产可在 OpenSea 上找到： <https://opensea.io/assets/0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536>.

以下是 *network*:

* `ethereum`：以太坊主网
* `matic`：Polygon Matic
* `klaytn`：Klaytn
* `bsc`：BNB Chain
* `arbitrum`：Arbitrum
* `arbitrum_nova`：Arbitrum Nova
* `avalanche`：Avalanche
* `optimism`：Optimism
* `solana`：Solana
* `base`：Base
* `blast`：Blast
* `zora`：Zora

{% hint style="warning" %}
**📔 注意**：图片大小不得超过 **6 MB**。如果图片过大，则不会在场景中渲染。
{% endhint %}

## 自定义边框

默认情况下，图片会带有紫色背景，周围有一个带脉动发光纹理的边框。你可以设置以下属性，使其更符合 NFT 和场景的风格：

* `color`：用于设置模型背面的颜色；如果 NFT 图片带有透明区域，也会用作图片的背景色。
* `style`：从若干预设选项组成的枚举中选择边框模型。使用枚举值 `NftFrameType`，其中列出了所有可用样式。

```ts
NftShape.create(nftEntity, {
  urn: 'urn:decentraland:ethereum:erc721:0x06012c8cf97bead5deae237070f9587f8e7a266d:558536',
  color: Color3.Green(),
  style: NftFrameType.NFT_GOLD_EDGES,
})
```

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-61d67dbd92e5421cd6de7e12d67ca5d6d1e81be7%2Fnft-frames.webp?alt=media)

以下是支持的所有边框样式：

* `NFT_CLASSIC`
* `NFT_BAROQUE_ORNAMENT`
* `NFT_DIAMOND_ORNAMENT`
* `NFT_MINIMAL_WIDE`
* `NFT_MINIMAL_GREY`
* `NFT_BLOCKY`
* `NFT_GOLD_EDGES`
* `NFT_GOLD_CARVED`
* `NFT_GOLD_WIDE`
* `NFT_GOLD_ROUNDED`
* `NFT_METAL_MEDIUM`
* `NFT_METAL_WIDE`
* `NFT_METAL_SLIM`
* `NFT_METAL_ROUNDED`
* `NFT_PINS`
* `NFT_MINIMAL_BLACK`
* `NFT_MINIMAL_WHITE`
* `NFT_TAPE`
* `NFT_WOOD_SLIM`
* `NFT_WOOD_WIDE`
* `NFT_WOOD_TWIGS`
* `NFT_CANVAS`
* `NFT_NONE`

有些相框使用的材质比其他相框多。例如，默认相框会为 NFT 本身添加 1 个材质，为背景色平面添加 1 个材质，并为相框添加 2 个材质（与其他同样式的相框共用）。如果需要减少材质数量以 [满足场景限制](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/you-hua/scene-limitations.md)，请选择更简单的样式。例如，"none" 样式仅为 NFT 本身使用 1 个材质。

{% hint style="info" %}
**💡 提示**：使用 Visual Studio Code（或其他 IDE），输入 `NftFrameType.` 并等待智能提示显示选项列表。使用 `NftFrameType.NFT_NONE`按原样显示不带相框或背景色的纯 NFT。
{% endhint %}

## 打开 NFT 界面

打开一个预构建界面，其中显示 NFT 的名称、所有者和描述。如果适用，该界面还会显示 NFT 的当前价格和最近一次售出价格，并提供一个按钮，链接到 OpenSea 上该 NFT 的页面；你可以在那里查看更多信息并购买 NFT。

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-a0bb4779b60d953b016b8406332ec3b57baefd71%2Fnft-ui.webp?alt=media)

调用函数 `openNftDialog()`即可打开此界面。此函数需要一个对象作为参数，其中包含一个 `urn` 字段。该字段接受一个字符串，格式如下：

`urn:decentraland:<CHAIN>:<CONTRACT_STANDARD>:<CONTRACT_ADDRESS>:<TOKEN_ID>`

例如：

`urn:decentraland:ethereum:erc721:0x00...000:123`

{% hint style="warning" %}
**📔 注意**：此界面必须由按钮事件触发打开，以防止滥用和垃圾信息。按钮事件不一定要发生在同一个相框上，也不一定要发生在 `NftShape`.
{% endhint %}

上。要通过点击操作打开此界面，请添加以下内容：

```ts
import { openNftDialog } from '~system/RestrictedActions'

// 添加指针碰撞体，使其可被点击
MeshCollider.setBox(myEntity, ColliderLayer.CL_POINTER)

// 添加 onPointerDown 回调事件。
pointerEventsSystem.onPointerDown(
	{
		entity: myEntity,
		opts: { button: InputAction.IA_PRIMARY, hoverText: 'Click' },
	},
	function () {
		openNftDialog({
			urn: 'urn:decentraland:ethereum:erc721:0x06012c8cf97BEaD5deAe237070F9587f8E7A266d:558536',
		})
	}
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/mei-ti/display-a-certified-nft.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
