快速入门
更新NFT
Last updated March 12, 2025
作为更新权限者更新NFT的名称和元数据。
更新NFT
在以下部分,您可以看到完整的代码示例以及需要更改的参数。有关更新NFT的更多详情,请参阅Core文档。
1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { update } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4import { publicKey } from '@metaplex-foundation/umi'
5
6const umi = createUmi('https://api.devnet.solana.com').use(mplCore())
7const assetAddress = publicKey('AssetAddressHere...')
8
9// Update an existing NFT asset's metadata
10const result = await update(umi, {
11 asset: assetAddress,
12 name: 'Updated NFT Name',
13 uri: 'https://updated-example.com/metadata.json',
14}).sendAndConfirm(umi)
15
16console.log('Asset updated successfully')
1# Update an NFT using the Metaplex CLI
2
3# Update name and URI
4mplx core asset update <assetId> --name "Updated NFT" --uri "https://example.com/new-metadata.json"
5
6# Update with new image
7mplx core asset update <assetId> --image "./new-image.png"
8
9# Update with JSON metadata file
10mplx core asset update <assetId> --json "./metadata.json"
11
12# Update with both JSON and image
13mplx core asset update <assetId> --json "./metadata.json" --image "./new-image.png"
参数
根据您的更新需求自定义以下参数:
| 参数 | 描述 |
|---|---|
assetAddress | 要更新的NFT的公钥 |
name | NFT的新名称(可选) |
uri | 新的元数据URI(可选) |
工作原理
更新过程涉及3个步骤:
- 获取NFT - 使用
fetchAsset获取当前NFT数据 - 准备更新 - 指定您想要更改的新名称或URI
- 提交更新 - 执行更新交易
只有NFT的更新权限者才能修改NFT。如果NFT是收藏集的一部分并使用收藏集权限,您需要是收藏集的更新权限者。
