功能

更新资产

只要 Is Mutable 属性设置为 true,资产的更新权限就可以使用 Update 指令更新其 Metadata 账户。Update 指令要求 Update Authority 签署交易,并可以更新 Metadata 账户的以下属性:

可更新字段

请注意,某些委托权限也可以更新资产的 Metadata 账户,如"委托权限"页面中所述。

以下是 UpdateV1 指令中所有可更新的单独字段的说明。

Data 对象

定义资产的 Name、Symbol、URI、Seller Fee Basis Points 和 Creators 数组的对象。请注意,更新权限只能从 Creators 数组中添加和/或删除未验证的创建者。唯一的例外是如果创建者是更新权限,在这种情况下,添加或删除的创建者可以被验证。

Data 对象

const data = {
name: 'New Name',
symbol: 'New Symbol',
uri: 'https://newuri.com',
sellerFeeBasisPoints: 500,
creators: [],
}

Primary Sale Happened

Primary Sale Happened:一个布尔值,指示资产是否已经被销售过。

Primary Sale Happened

primarySaleHappened: true

Is Mutable

一个布尔值,指示资产是否可以再次更新。当将其更改为 false 时,任何未来的更新都将失败。

Is Mutable

isMutable: true

Collection

此属性使我们能够设置或清除资产的集合。请注意,在设置新集合时,verified 布尔值必须设置为 false,并使用另一个指令进行验证

设置集合

设置集合

collection: collectionToggle('Set', [
{
key: publicKey('11111111111111111111111111111111'),
verified: false,
},
])

清除集合

清除集合

collection: collectionToggle("Clear"),

New Update Authority

可以通过传入 newUpdateAuthority 字段将新的更新权限分配给资产。

New Update Authority

newUpdateAuthority: publicKey('1111111111111111111111111111111')

Programable RuleSets

此属性使我们能够设置或清除资产的规则集。这仅与可编程非同质化代币相关。

Programable RuleSets

ruleSet: publicKey('1111111111111111111111111111111')

以下是如何使用我们的 SDK 在 Token Metadata 上更新资产。

作为更新权限进行更新

NFT 资产

此示例向您展示如何作为资产的更新权限更新 NFT 资产。

1import { publicKey, none, some } from '@metaplex-foundation/umi';
2import { updateV1 } from '@metaplex-foundation/mpl-token-metadata';
3
4// Assuming umi is set up with mplTokenMetadata plugin
5// See getting-started for full setup
6
7const mintAddress = publicKey('mintAddress...');
8
9// Update the NFT metadata
10await updateV1(umi, {
11 mint: mintAddress,
12 authority: umi.identity,
13 // Only specify fields you want to update
14 data: some({
15 name: 'Updated NFT Name',
16 symbol: '', // Keep existing
17 uri: '', // Keep existing
18 sellerFeeBasisPoints: 0, // Keep existing
19 creators: none(),
20 }),
21}).sendAndConfirm(umi);
22
23console.log('NFT metadata updated');

pNFT 资产

此示例向您展示如何作为资产的更新权限更新可编程 NFT (pNFT) 资产。

pNFTs 可能需要传入附加账户才能使指令工作。这些包括:tokenAccount、tokenRecord、authorizationRules 和 authorizationRulesProgram。

1import { publicKey, none, some } from '@metaplex-foundation/umi';
2import { updateV1 } from '@metaplex-foundation/mpl-token-metadata';
3
4// Assuming umi is set up with mplTokenMetadata plugin
5
6const mintAddress = publicKey('mintAddress...');
7
8// Update the Programmable NFT metadata
9// Note: pNFTs may have rule sets that restrict updates
10await updateV1(umi, {
11 mint: mintAddress,
12 authority: umi.identity,
13 data: some({
14 name: 'Updated pNFT Name',
15 symbol: '',
16 uri: '',
17 sellerFeeBasisPoints: 0,
18 creators: none(),
19 }),
20}).sendAndConfirm(umi);
21
22console.log('pNFT metadata updated');