功能

更新压缩NFT

Last updated June 19, 2026

Summary

Updating a compressed NFT modifies its metadata using the updateMetadataV2 instruction. This page covers update authority rules for collection-based and tree-based cNFTs.

  • Update cNFT metadata (name, URI, creators, royalties) using updateMetadataV2
  • Collection authority updates cNFTs that belong to a collection
  • Tree authority updates cNFTs that do not belong to a collection
  • Changes are reflected in the merkle tree and indexed by DAS API providers
  • 向 updateMetadataV2 展开 ...assetWithProof,使用 getAssetWithProof.currentMetadata(叶子规范值)

updateMetadataV2指令可用于修改压缩NFT的元数据。默克尔根会更新以反映数据的传播哈希,符合Metaplex DAS API的RPC提供商将更新其cNFT索引。

元数据可以由两个权限之一更新,具体取决于压缩NFT是否是集合中的已验证项目。

更新权限

cNFT有两个可能的更新权限:树所有者,或(如果属于集合)集合权限。

集合权限

如果您的cNFT属于某个集合,那么该cNFT的更新权限将是集合的权限。更新cNFT时,您需要向更新函数传递coreCollection参数。

权限将从当前umi身份推断。如果权限与当前umi身份不同,则您需要将authority参数作为签名者类型传入,或创建一个noopSigner以便稍后签名。

await updateMetadataV2(umi, {
...
authority: collectionAuthority,
coreCollection: publicKey("11111111111111111111111111111111"),
}).sendAndConfirm(umi)

树权限

如果您的cNFT不属于集合,那么cNFT的更新权限将是cNFT所属树的权限。在这种情况下,您应该从更新函数中省略coreCollection参数。

权限将从当前umi身份推断。如果权限与当前umi身份不同,则您需要将authority参数作为签名者类型传入,或创建一个noopSigner以便稍后签名。

更新cNFT

更新压缩NFT

import {
getAssetWithProof,
updateMetadataV2,
UpdateArgsArgs,
} from '@metaplex-foundation/mpl-bubblegum'
import { some } from '@metaplex-foundation/umi'
// 使用辅助函数获取资产和证明。
const assetWithProof = await getAssetWithProof(umi, assetId, {
truncateCanopy: true,
})
// 然后我们可以用它来更新NFT的元数据。
const updateArgs: UpdateArgsArgs = {
name: some('New name'),
uri: some('https://updated-example.com/my-nft.json'),
}
await updateMetadataV2(umi, {
...assetWithProof,
leafOwner,
updateArgs,
// 可选参数。如果您的权限是与当前umi身份不同的签名者类型,
// 在此处分配该签名者。
authority: <Signer>,
// 可选参数。如果cNFT属于集合,在此处传递。
coreCollection: publicKey("22222222222222222222222222222222"),
}).sendAndConfirm(umi)

写入指令使用叶子元数据

getAssetWithProof 同时返回 metadata(DAS 展示 / 解析费率)和 currentMetadata(叶子规范 MetadataArgsV2Args,继承时为 65535)。写入时展开 ...assetWithProof,不要把展示用 metadata 当作 currentMetadata。UI 使用 metadata / rpcAsset;用 inherited 检测继承。

读取资产时关于 DAS 响应字段的说明,请参阅读取继承版税。

继承版税

通过将 updateArgs.sellerFeeBasisPoints 设为 some(SELLER_FEE_BASIS_POINTS_INHERIT),可将 cNFT 切换为继承版税。集合必须具有 Royalties 插件,且更新后的元数据 creators 数组必须为空。

要从继承版税切换回明确百分比 — 例如在从集合中移除 cNFT之前 — 请传入所需的 basis points:

1import {
2 getAssetWithProof,
3 updateMetadataV2,
4 UpdateArgsArgs,
5 mplBubblegum,
6} from '@metaplex-foundation/mpl-bubblegum'
7import { dasApi } from '@metaplex-foundation/digital-asset-standard-api'
8import { keypairIdentity, publicKey, some } from '@metaplex-foundation/umi'
9import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
10import { readFileSync } from 'fs'
11
12// getAssetWithProof calls getAsset and getAssetProof, so this needs a
13// DAS-capable RPC. The public Solana endpoints do not serve DAS methods.
14const umi = createUmi('YOUR_DAS_ENABLED_RPC_URL')
15 .use(mplBubblegum())
16 .use(dasApi())
17
18// The leaf owner or an authorised delegate must sign the update.
19const keypair = umi.eddsa.createKeypairFromSecretKey(
20 new Uint8Array(JSON.parse(readFileSync('./keypair.json', 'utf8')))
21)
22umi.use(keypairIdentity(keypair))
23
24const assetId = publicKey('YOUR_ASSET_ID')
25const collectionPublicKey = publicKey('YOUR_COLLECTION_ADDRESS')
26
27const assetWithProof = await getAssetWithProof(umi, assetId, {
28 truncateCanopy: true,
29})
30
31// Switch from inherited royalties to an explicit seller fee before removing
32// the cNFT from its collection.
33const updateArgs: UpdateArgsArgs = {
34 sellerFeeBasisPoints: some(550), // explicit 5.5%
35}
36
37// Spread includes currentMetadata (leaf-canonical). Do not pass metadata here.
38await updateMetadataV2(umi, {
39 ...assetWithProof,
40 updateArgs,
41 coreCollection: collectionPublicKey,
42}).sendAndConfirm(umi)
43
44// Leaf seller fee updated from inherit sentinel (65535) to 550 basis points

Notes

  • The update authority depends on whether the cNFT belongs to a collection. Collection cNFTs use the collection authority; standalone cNFTs use the tree authority.
  • 向 updateMetadataV2 展开 ...assetWithProof,以便程序用叶子规范的 currentMetadata 验证。
  • Use some() for fields you want to update and omit fields you want to keep unchanged.
  • Inherited seller fees require an empty leaf-level creators array and a collection with the Royalties plugin.

FAQ

谁可以更新压缩 NFT 的元数据?

如果 cNFT 属于集合,只有集合权限可以更新。如果不属于集合,树权限(树创建者或委托人)可以更新。

可以在 cNFT 上更新哪些字段?

你可以更新 UpdateArgsArgs 中定义的名称、URI、seller fee basis points 及其他元数据字段。对要更改的字段使用 some('newValue')。

更新时需要传递集合吗?

是的,如果 cNFT 属于集合。请传递带有集合公钥的 coreCollection 参数。集合权限必须签署交易。

如何更新从集合继承版税的 cNFT?

向 updateMetadataV2 展开 ...assetWithProof,继承时 currentMetadata 会带上链上哨兵。使用 updateArgs.sellerFeeBasisPoints 的 some(SELLER_FEE_BASIS_POINTS_INHERIT) 切换为继承版税,或使用明确数字离开继承。

Glossary

TermDefinition
updateMetadataV2The Bubblegum V2 instruction for modifying compressed NFT metadata
Collection AuthorityThe update authority of the MPL-Core collection, authorized to update cNFTs in that collection
Tree AuthorityThe tree creator or delegate, authorized to update cNFTs that do not belong to a collection
UpdateArgsArgsThe TypeScript type defining which metadata fields to update, using Option wrappers
currentMetadataupdateMetadataV2 上表示现有叶子元数据的 IDL 参数;展开 ...assetWithProof 时由 getAssetWithProof.currentMetadata 提供
SELLER_FEE_BASIS_POINTS_INHERITSentinel value 65535 indicating royalties are inherited from the MPL-Core collection