기능
자산 업데이트
자산의 업데이트 권한은 Is Mutable 속성이 true로 설정되어 있는 한 Update 명령어를 사용하여 Metadata 계정을 업데이트할 수 있습니다. Update 명령어는 업데이트 권한이 트랜잭션에 서명하는 것을 요구하며 Metadata 계정의 다음 속성을 업데이트할 수 있습니다:
업데이트 가능한 필드
특정 위임된 권한도 "위임된 권한" 페이지에서 논의된 바와 같이 자산의 Metadata 계정을 업데이트할 수 있다는 점에 주목하세요.
아래는 UpdateV1 명령어에서 업데이트할 수 있는 모든 개별 필드에 대한 설명입니다.
데이터 객체
자산의 이름, 심볼, URI, 판매자 수수료 기준점 및 크리에이터 배열을 정의하는 객체입니다. 업데이트 권한은 크리에이터 배열에서 확인되지 않은 크리에이터만 추가 및/또는 제거할 수 있다는 점에 주목하세요. 유일한 예외는 크리에이터가 업데이트 권한인 경우이며, 이 경우 추가되거나 제거된 크리에이터가 확인될 수 있습니다.
데이터 객체
const data = {
name: 'New Name',
symbol: 'New Symbol',
uri: 'https://newuri.com',
sellerFeeBasisPoints: 500,
creators: [],
}
1차 판매 발생
1차 판매 발생: 자산이 이전에 판매되었는지를 나타내는 불리언 값입니다.
1차 판매 발생
primarySaleHappened: true
변경 가능
자산을 다시 업데이트할 수 있는지를 나타내는 불리언 값입니다. 이를 false로 변경하면 향후 모든 업데이트가 실패합니다.
변경 가능
isMutable: true
컬렉션
이 속성을 통해 자산의 컬렉션을 설정하거나 지울 수 있습니다. 새 컬렉션을 설정할 때 verified 불리언은 false로 설정되어야 하며 다른 명령어를 사용하여 확인되어야 한다는 점에 주목하세요.
컬렉션 설정
컬렉션 설정
collection: collectionToggle('Set', [
{
key: publicKey('11111111111111111111111111111111'),
verified: false,
},
])
컬렉션 지우기
컬렉션 지우기
collection: collectionToggle("Clear"),
새 업데이트 권한
newUpdateAuthority 필드를 전달하여 자산에 새로운 업데이트 권한을 할당할 수 있습니다.
새 업데이트 권한
newUpdateAuthority: publicKey('1111111111111111111111111111111')
프로그래머블 RuleSet
이 속성을 통해 자산의 규칙 세트를 설정하거나 지울 수 있습니다. 이는 프로그래머블 대체 불가능에만 관련이 있습니다.
프로그래머블 RuleSet
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');
1import {
2 getUpdateV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and authority are set up
7// See getting-started for full setup
8
9const mintAddress = 'mintAddress...'; // The NFT mint address
10
11// Update the NFT metadata
12const updateIx = await getUpdateV1InstructionAsync({
13 mint: mintAddress,
14 authority,
15 payer: authority,
16 // Specify fields to update (creators must be explicitly set, use null to keep existing)
17 data: {
18 name: 'Updated NFT Name',
19 symbol: 'UNFT',
20 uri: 'https://example.com/updated-nft.json',
21 sellerFeeBasisPoints: 550,
22 creators: null, // Keep existing creators
23 },
24});
25
26await sendAndConfirm({
27 instructions: [updateIx],
28 payer: authority,
29});
30
31console.log('NFT metadata updated');
1use anchor_lang::prelude::*;
2use mpl_token_metadata::{
3 accounts::Metadata,
4 instructions::UpdateAsUpdateAuthorityV2CpiBuilder, types::Data,
5};
6
7#[derive(Accounts)]
8pub struct NftUpdateMpl<'info> {
9 pub mint: AccountInfo<'info>,
10 /// CHECK: Handled by CPI
11 #[account(mut)]
12 pub metadata: AccountInfo<'info>,
13 #[account(mut)]
14 pub update_authority: Signer<'info>,
15 /// CHECK: Handled by CPI
16 pub token_metadata_program: AccountInfo<'info>,
17}
18
19pub fn update_nft_mpl_instruction<'info>(
20 ctx: Context<'_, '_, '_, 'info, NftUpdateMpl<'info>>,
21 new_name: Option<String>,
22 new_uri: Option<String>,
23) -> Result<()> {
24 let mint = ctx.accounts.mint.to_account_info();
25 let metadata = ctx.accounts.metadata.to_account_info();
26 let token_metadata_program = ctx.accounts.token_metadata_program.to_account_info();
27
28 // Get the original metadata values
29 let metadata_account = Metadata::try_from(&metadata)?;
30
31 let original_metadata = Data {
32 name: metadata_account.name,
33 symbol: metadata_account.symbol,
34 uri: metadata_account.uri,
35 seller_fee_basis_points: metadata_account.seller_fee_basis_points,
36 creators: metadata_account.creators,
37 };
38
39 let new_metadata = Data {
40 name: new_name.unwrap_or(original_metadata.name),
41 uri: new_uri.unwrap_or(original_metadata.uri),
42 ..original_metadata // Keep the rest of the metadata the same
43 };
44
45 UpdateAsUpdateAuthorityV2CpiBuilder::new(&token_metadata_program)
46 .mint(&mint)
47 .metadata(&metadata)
48 .authority(&ctx.accounts.update_authority)
49 .data(new_metadata)
50 // Add remaining data fields/accounts to be adjusted to the CPI if needed
51 // https://docs.rs/mpl-token-metadata/latest/mpl_token_metadata/instructions/struct.UpdateAsUpdateAuthorityV2CpiBuilder.html
52 .invoke()?;
53
54 Ok(())
55}
pNFT 자산
이 예제는 자산의 업데이트 권한으로서 프로그래머블 NFT (pNFT) 자산을 업데이트하는 방법을 보여줍니다.
pNFT는 명령어가 작동하기 위해 추가 계정을 전달해야 할 수 있습니다. 여기에는 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');
1import {
2 getUpdateV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and authority are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Update the Programmable NFT metadata
11// Note: pNFTs may have rule sets that restrict updates
12const updateIx = await getUpdateV1InstructionAsync({
13 mint: mintAddress,
14 authority,
15 payer: authority,
16 // Specify fields to update (creators must be explicitly set, use null to keep existing)
17 data: {
18 name: 'Updated pNFT Name',
19 symbol: 'UPNFT',
20 uri: 'https://example.com/updated-pnft.json',
21 sellerFeeBasisPoints: 550,
22 creators: null, // Keep existing creators
23 },
24});
25
26await sendAndConfirm({
27 instructions: [updateIx],
28 payer: authority,
29});
30
31console.log('pNFT metadata updated');
1use anchor_lang::prelude::*;
2use mpl_token_metadata::{
3 accounts::Metadata,
4 instructions::UpdateAsUpdateAuthorityV2CpiBuilder, types::Data,
5};
6
7#[derive(Accounts)]
8pub struct NftUpdateMpl<'info> {
9 pub mint: AccountInfo<'info>,
10 /// CHECK: Handled by CPI
11 #[account(mut)]
12 pub metadata: AccountInfo<'info>,
13 #[account(mut)]
14 pub update_authority: Signer<'info>,
15 /// CHECK: Handled by CPI
16 pub token_metadata_program: AccountInfo<'info>,
17 // Add additional accounts below if needed
18}
19
20pub fn update_nft_mpl_instruction<'info>(
21 ctx: Context<'_, '_, '_, 'info, NftUpdateMpl<'info>>,
22 new_name: Option<String>,
23 new_uri: Option<String>,
24) -> Result<()> {
25 let mint = ctx.accounts.mint.to_account_info();
26 let metadata = ctx.accounts.metadata.to_account_info();
27 let token_metadata_program = ctx.accounts.token_metadata_program.to_account_info();
28
29 // Get the original metadata values
30 let metadata_account = Metadata::try_from(&metadata)?;
31
32 let original_metadata = Data {
33 name: metadata_account.name,
34 symbol: metadata_account.symbol,
35 uri: metadata_account.uri,
36 seller_fee_basis_points: metadata_account.seller_fee_basis_points,
37 creators: metadata_account.creators,
38 };
39
40 let new_metadata = Data {
41 name: new_name.unwrap_or(original_metadata.name),
42 uri: new_uri.unwrap_or(original_metadata.uri),
43 ..original_metadata // Keep the rest of the metadata the same
44 };
45
46 UpdateAsUpdateAuthorityV2CpiBuilder::new(&token_metadata_program)
47 .mint(&mint)
48 .metadata(&metadata)
49 .authority(&ctx.accounts.update_authority)
50 .data(new_metadata)
51
52 // Add remaining data fields to be adjusted to the CPI if needed
53 // https://docs.rs/mpl-token-metadata/latest/mpl_token_metadata/instructions/struct.UpdateAsUpdateAuthorityV2CpiBuilder.html
54 //
55 // .authorization_rules(authorization_rules)
56 // .authorization_rules_program(authorization_rules_program)
57 // .token_record(token_record)
58 .invoke()?;
59
60 Ok(())
61}
