Token Metadata 是旧版程序。仍受支持,但不建议用于新项目。 请改用Core。
功能
委托权限
对我们的资产只有单一权限并不总是理想的。有时我们希望将其中一些职责委托给其他钱包或程序,以便它们可以代表我们做事。这就是为什么 Token Metadata 提供了一整套具有不同作用域的委托。
元数据委托与代币委托
Token Metadata 提供的委托可以分为两类:元数据委托和代币委托。我们将在下面详细介绍它们,但让我们先快速了解一下它们的区别。
- 元数据委托与资产的铸造账户相关联,并允许委托权限对元数据账户执行更新。它们由资产的更新权限批准,并且可以根据需要有任意多个。
- 代币委托与资产的代币账户相关联,并允许委托权限转移、销毁和/或锁定代币。它们由资产的所有者批准,每个代币账户一次只能有一个。
元数据委托
元数据委托是在元数据级别操作的委托。这些委托使用元数据委托记录 PDA 存储——其种子为 ["metadata", program id, mint id, delegate role, update authority id, delegate id]。
该账户跟踪委托权限以及批准它的更新权限。
以下是元数据委托的一些关键属性:
- 给定资产可以有任意多个元数据委托。
- 元数据委托从铸造账户派生,这意味着它们的存在与资产的所有者无关。因此,转移资产不会影响元数据委托。
- 元数据委托也从资产的当前更新权限派生。这意味着,每当资产上的更新权限被更新时,所有元数据委托都会失效,新的更新权限无法使用。但是,如果更新权限被转移回来,所有与之关联的元数据委托将自动重新激活。
- 元数据委托可以由批准它们的更新权限撤销。
- 元数据委托也可以自行撤销。
存在 7 种不同类型的元数据委托,每种都有不同的操作范围。以下是总结不同类型元数据委托的表格:
| 委托 | 自我更新 | 更新集合中的项目 | 更新范围 |
|---|---|---|---|
| Authority Item | ✅ | ❌ | newUpdateAuthority ,primarySaleHappened ,isMutable ,tokenStandard |
| Collection | ✅ | ✅ | collection + 验证/取消验证项目上的集合 |
| Collection Item | ✅ | ❌ | collection |
| Data | ✅ | ✅ | data |
| Data Item | ✅ | ❌ | data |
| Programmable Configs | ✅ | ✅ | programmableConfigs |
| Programmable Configs Item | ✅ | ❌ | programmableConfigs |
请注意,名称以 Item 结尾的元数据委托只能对自己进行操作,而其他委托还可以对委托资产的集合项目进行操作。例如,假设我们有一个包含 NFT B 和 C 的集合 NFT A。当我们在 A 上批准数据委托时,我们可以更新 NFT A、B 和 C 的 data 对象。但是,当我们在 A 上批准数据项委托时,我们只能更新 NFT A 的 data 对象。
此外,集合委托有点特殊,因为它还允许我们在集合的项目上验证/取消验证委托的 NFT。在上面的例子中,当我们在 A 上批准集合委托时,我们可以在 NFT B 和 C 上验证/取消验证该集合。
让我们更详细地介绍每个元数据委托,并提供批准、撤销和使用它们的代码示例。
Authority Item 委托
- 委托权限可以更新资产的一个子集。它可以更新元数据账户的以下属性:
newUpdateAuthority:将更新权限转移到另一个账户。primarySaleHappened:在资产的主要销售发生时切换为true。isMutable:切换为false使资产不可变。tokenStandard:如果资产是在强制设置之前创建的,可以设置代币标准。
1import { delegateAuthorityItemV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, updateAuthority, and authorityItemDelegate are set up
4
5await delegateAuthorityItemV1(umi, {
6 mint,
7 authority: updateAuthority,
8 delegate: authorityItemDelegate,
9 tokenStandard: TokenStandard.NonFungible,
10}).sendAndConfirm(umi);
11
12console.log('Authority Item delegate approved');
1import {
2 getDelegateAuthorityItemV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, updateAuthority, and authorityItemDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Approve an Authority Item delegate
11const delegateIx = await getDelegateAuthorityItemV1InstructionAsync({
12 mint: mintAddress,
13 delegate: authorityItemDelegate,
14 authority: updateAuthority,
15 payer: updateAuthority,
16 tokenStandard: TokenStandard.NonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [delegateIx],
21 payer: updateAuthority,
22});
23
24console.log('Authority Item delegate approved');
1import { revokeAuthorityItemV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, updateAuthority, and authorityItemDelegate are set up
4
5await revokeAuthorityItemV1(umi, {
6 mint,
7 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke.
8 delegate: authorityItemDelegate,
9 tokenStandard: TokenStandard.NonFungible,
10}).sendAndConfirm(umi);
11
12console.log('Authority Item delegate revoked');
1import {
2 getRevokeAuthorityItemV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, updateAuthority, and authorityItemDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Revoke an Authority Item delegate
11// Note: Either the update authority or the delegate itself can revoke
12const revokeIx = await getRevokeAuthorityItemV1InstructionAsync({
13 mint: mintAddress,
14 delegate: authorityItemDelegate,
15 authority: updateAuthority, // Or pass the delegate to self-revoke
16 payer: updateAuthority,
17 tokenStandard: TokenStandard.NonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [revokeIx],
22 payer: updateAuthority,
23});
24
25console.log('Authority Item delegate revoked');
1import { updateAsAuthorityItemDelegateV2 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, authorityItemDelegate, and newUpdateAuthority are set up
4
5await updateAsAuthorityItemDelegateV2(umi, {
6 mint,
7 authority: authorityItemDelegate,
8 newUpdateAuthority,
9 isMutable: false,
10}).sendAndConfirm(umi);
11
12console.log('Asset updated by Authority Item delegate');
1import {
2 getUpdateAsAuthorityItemDelegateV2InstructionAsync,
3} from '@metaplex-foundation/mpl-token-metadata-kit';
4
5// Assuming rpc, rpcSubscriptions, sendAndConfirm, and authorityItemDelegate are set up
6
7const mintAddress = 'mintAddress...'; // The NFT mint address
8const newUpdateAuthority = 'newUpdateAuthorityAddress...';
9
10// Update as Authority Item delegate
11const updateIx = await getUpdateAsAuthorityItemDelegateV2InstructionAsync({
12 mint: mintAddress,
13 authority: authorityItemDelegate,
14 payer: authorityItemDelegate,
15 newUpdateAuthority,
16 isMutable: false,
17});
18
19await sendAndConfirm({
20 instructions: [updateIx],
21 payer: authorityItemDelegate,
22});
23
24console.log('Asset updated by Authority Item delegate');
Collection 委托
- 委托权限可以更新资产的一个子集。它可以设置元数据账户的
collection属性。 - 当应用于集合 NFT 时,委托权限可以对该集合中的项目执行以下操作:
- 它可以在项目上验证和取消验证该集合 NFT。只有当集合 NFT 已经在项目上设置时才能执行此操作。否则,无法知道该项目是否属于委托的集合 NFT。
- 它可以从项目中清除集合 NFT。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateCollectionV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const collectionDelegate = publicKey('delegateAddress...');
10
11await delegateCollectionV1(umi, {
12 mint,
13 authority: updateAuthority,
14 delegate: collectionDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Collection delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateCollectionV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const collectionDelegate = address('delegateAddress...');
9
10const delegateIx = await getDelegateCollectionV1InstructionAsync({
11 mint,
12 authority: updateAuthority,
13 delegate: collectionDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [delegateIx],
19 payer: updateAuthority,
20});
21
22console.log('Collection delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeCollectionV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const collectionDelegate = publicKey('delegateAddress...');
10
11await revokeCollectionV1(umi, {
12 mint,
13 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
14 delegate: collectionDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Collection delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeCollectionV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const collectionDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeCollectionV1InstructionAsync({
11 mint,
12 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
13 delegate: collectionDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [revokeIx],
19 payer: updateAuthority,
20});
21
22console.log('Collection delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsCollectionDelegateV2,
4 collectionToggle,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const collectionDelegate = umi.identity; // The delegate authority
9const collectionMint = publicKey('collectionMintAddress...');
10
11await updateAsCollectionDelegateV2(umi, {
12 mint,
13 authority: collectionDelegate,
14 collection: collectionToggle('Set', [
15 { key: collectionMint, verified: false },
16 ]),
17}).sendAndConfirm(umi);
18
19console.log('Collection set on asset');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsCollectionDelegateV2InstructionAsync,
4 CollectionToggle,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const collectionMint = address('collectionMintAddress...');
9
10const updateIx = await getUpdateAsCollectionDelegateV2InstructionAsync({
11 mint,
12 authority: collectionDelegate,
13 collection: {
14 __kind: 'Set',
15 fields: [{ key: collectionMint, verified: false }],
16 },
17});
18
19await sendAndConfirm({
20 instructions: [updateIx],
21 payer: collectionDelegate,
22});
23
24console.log('Collection set on asset');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsCollectionDelegateV2,
4 collectionToggle,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...'); // The item to clear collection from
8const collectionMint = publicKey('collectionMintAddress...');
9const collectionDelegate = umi.identity; // The delegate authority
10
11await updateAsCollectionDelegateV2(umi, {
12 mint,
13 delegateMint: collectionMint,
14 authority: collectionDelegate,
15 collection: collectionToggle('Clear'),
16}).sendAndConfirm(umi);
17
18console.log('Collection cleared from item');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsCollectionDelegateV2InstructionAsync,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6const mint = address('mintAddress...'); // The item to clear collection from
7const collectionMint = address('collectionMintAddress...');
8
9const updateIx = await getUpdateAsCollectionDelegateV2InstructionAsync({
10 mint,
11 delegateMint: collectionMint,
12 authority: collectionDelegate,
13 collection: { __kind: 'Clear' },
14});
15
16await sendAndConfirm({
17 instructions: [updateIx],
18 payer: collectionDelegate,
19});
20
21console.log('Collection cleared from item');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 verifyCollectionV1,
4 findMetadataPda,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...'); // The item to verify
8const collectionMint = publicKey('collectionMintAddress...');
9const collectionDelegate = umi.identity; // The delegate authority
10
11await verifyCollectionV1(umi, {
12 metadata: findMetadataPda(umi, { mint }),
13 collectionMint,
14 authority: collectionDelegate,
15}).sendAndConfirm(umi);
16
17console.log('Collection verified on item');
1import { address } from '@solana/addresses';
2import {
3 getVerifyCollectionV1InstructionAsync,
4 findMetadataPda,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...'); // The item to verify
8const collectionMint = address('collectionMintAddress...');
9
10const [metadata] = await findMetadataPda({ mint });
11const verifyIx = await getVerifyCollectionV1InstructionAsync({
12 metadata,
13 collectionMint,
14 authority: collectionDelegate,
15});
16
17await sendAndConfirm({
18 instructions: [verifyIx],
19 payer: collectionDelegate,
20});
21
22console.log('Collection verified on item');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 unverifyCollectionV1,
4 findMetadataPda,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...'); // The item to unverify
8const collectionMint = publicKey('collectionMintAddress...');
9const collectionDelegate = umi.identity; // The delegate authority
10
11await unverifyCollectionV1(umi, {
12 metadata: findMetadataPda(umi, { mint }),
13 collectionMint,
14 authority: collectionDelegate,
15}).sendAndConfirm(umi);
16
17console.log('Collection unverified on item');
1import { address } from '@solana/addresses';
2import {
3 getUnverifyCollectionV1InstructionAsync,
4 findMetadataPda,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...'); // The item to unverify
8const collectionMint = address('collectionMintAddress...');
9
10const [metadata] = await findMetadataPda({ mint });
11const unverifyIx = await getUnverifyCollectionV1InstructionAsync({
12 metadata,
13 collectionMint,
14 authority: collectionDelegate,
15});
16
17await sendAndConfirm({
18 instructions: [unverifyIx],
19 payer: collectionDelegate,
20});
21
22console.log('Collection unverified on item');
Collection Item 委托
- 委托权限可以更新资产的一个子集。它可以设置元数据账户的
collection属性。 - 即使资产是集合 NFT,与集合委托相反,集合项委托也不能影响该集合的项目。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateCollectionItemV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const collectionItemDelegate = publicKey('delegateAddress...');
10
11await delegateCollectionItemV1(umi, {
12 mint,
13 authority: updateAuthority,
14 delegate: collectionItemDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Collection Item delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateCollectionItemV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const collectionItemDelegate = address('delegateAddress...');
9
10const delegateIx = await getDelegateCollectionItemV1InstructionAsync({
11 mint,
12 authority: updateAuthority,
13 delegate: collectionItemDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [delegateIx],
19 payer: updateAuthority,
20});
21
22console.log('Collection Item delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeCollectionItemV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const collectionItemDelegate = publicKey('delegateAddress...');
10
11await revokeCollectionItemV1(umi, {
12 mint,
13 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
14 delegate: collectionItemDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Collection Item delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeCollectionItemV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const collectionItemDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeCollectionItemV1InstructionAsync({
11 mint,
12 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
13 delegate: collectionItemDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [revokeIx],
19 payer: updateAuthority,
20});
21
22console.log('Collection Item delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsCollectionItemDelegateV2,
4 collectionToggle,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const collectionMint = publicKey('collectionMintAddress...');
9const collectionItemDelegate = umi.identity; // The delegate authority
10
11await updateAsCollectionItemDelegateV2(umi, {
12 mint,
13 authority: collectionItemDelegate,
14 collection: collectionToggle('Set', [
15 { key: collectionMint, verified: false },
16 ]),
17}).sendAndConfirm(umi);
18
19console.log('Collection set on asset via Collection Item delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsCollectionItemDelegateV2InstructionAsync,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6const mint = address('mintAddress...');
7const collectionMint = address('collectionMintAddress...');
8
9const updateIx = await getUpdateAsCollectionItemDelegateV2InstructionAsync({
10 mint,
11 authority: collectionItemDelegate,
12 collection: {
13 __kind: 'Set',
14 fields: [{ key: collectionMint, verified: false }],
15 },
16});
17
18await sendAndConfirm({
19 instructions: [updateIx],
20 payer: collectionItemDelegate,
21});
22
23console.log('Collection set on asset via Collection Item delegate');
Data 委托
- 委托权限可以更新资产的一个子集。它可以更新元数据账户的整个
data对象,但不能更新其他内容。这意味着它可以更新资产的creators。 - 请注意,当更新
data对象中的creators数组时,它只能添加和/或删除未验证的创作者。 - 当应用于集合 NFT 时,委托权限可以对该集合中的项目执行相同的更新。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateDataV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const dataDelegate = publicKey('delegateAddress...');
10
11await delegateDataV1(umi, {
12 mint,
13 authority: updateAuthority,
14 delegate: dataDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Data delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateDataV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const dataDelegate = address('delegateAddress...');
9
10const delegateIx = await getDelegateDataV1InstructionAsync({
11 mint,
12 authority: updateAuthority,
13 delegate: dataDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [delegateIx],
19 payer: updateAuthority,
20});
21
22console.log('Data delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeDataV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const dataDelegate = publicKey('delegateAddress...');
10
11await revokeDataV1(umi, {
12 mint,
13 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
14 delegate: dataDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Data delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeDataV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const dataDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeDataV1InstructionAsync({
11 mint,
12 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
13 delegate: dataDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [revokeIx],
19 payer: updateAuthority,
20});
21
22console.log('Data delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsDataDelegateV2,
4 fetchMetadataFromSeeds,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const dataDelegate = umi.identity; // The delegate authority
9
10const initialMetadata = await fetchMetadataFromSeeds(umi, { mint });
11await updateAsDataDelegateV2(umi, {
12 mint,
13 authority: dataDelegate,
14 data: { ...initialMetadata, name: 'Updated Name' },
15}).sendAndConfirm(umi);
16
17console.log('Asset data updated via Data delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsDataDelegateV2InstructionAsync,
4 fetchMetadata,
5 findMetadataPda,
6} from '@metaplex-foundation/mpl-token-metadata-kit';
7
8const mint = address('mintAddress...');
9
10const [metadataAddress] = await findMetadataPda({ mint });
11const initialMetadata = await fetchMetadata(rpc, metadataAddress);
12
13const updateIx = await getUpdateAsDataDelegateV2InstructionAsync({
14 mint,
15 authority: dataDelegate,
16 data: {
17 ...initialMetadata,
18 name: 'Updated Name',
19 creators: null, // Required when passing data
20 },
21});
22
23await sendAndConfirm({
24 instructions: [updateIx],
25 payer: dataDelegate,
26});
27
28console.log('Asset data updated via Data delegate');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsDataDelegateV2,
4 fetchMetadataFromSeeds,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...'); // The collection item to update
8const collectionMint = publicKey('collectionMintAddress...');
9const dataDelegate = umi.identity; // The delegate authority (delegated on collection)
10
11const initialMetadata = await fetchMetadataFromSeeds(umi, { mint });
12await updateAsDataDelegateV2(umi, {
13 mint,
14 delegateMint: collectionMint,
15 authority: dataDelegate,
16 data: { ...initialMetadata, name: 'Updated Name' },
17}).sendAndConfirm(umi);
18
19console.log('Collection item data updated via Data delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsDataDelegateV2InstructionAsync,
4 fetchMetadata,
5 findMetadataPda,
6} from '@metaplex-foundation/mpl-token-metadata-kit';
7
8const mint = address('mintAddress...'); // The collection item to update
9const collectionMint = address('collectionMintAddress...');
10
11const [metadataAddress] = await findMetadataPda({ mint });
12const initialMetadata = await fetchMetadata(rpc, metadataAddress);
13
14const updateIx = await getUpdateAsDataDelegateV2InstructionAsync({
15 mint,
16 delegateMint: collectionMint,
17 authority: dataDelegate,
18 data: {
19 ...initialMetadata,
20 name: 'Updated Name',
21 creators: null, // Required when passing data
22 },
23});
24
25await sendAndConfirm({
26 instructions: [updateIx],
27 payer: dataDelegate,
28});
29
30console.log('Collection item data updated via Data delegate');
Data Item 委托
- 委托权限可以更新资产的一个子集。它可以更新元数据账户的整个
data对象,但不能更新其他内容。这意味着它可以更新资产的creators。 - 请注意,当更新
data对象中的creators数组时,它只能添加和/或删除未验证的创作者。 - 即使资产是集合 NFT,与数据委托相反,数据项委托也不能影响该集合的项目。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateDataItemV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const dataItemDelegate = publicKey('delegateAddress...');
10
11await delegateDataItemV1(umi, {
12 mint,
13 authority: updateAuthority,
14 delegate: dataItemDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Data Item delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateDataItemV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const dataItemDelegate = address('delegateAddress...');
9
10const delegateIx = await getDelegateDataItemV1InstructionAsync({
11 mint,
12 authority: updateAuthority,
13 delegate: dataItemDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [delegateIx],
19 payer: updateAuthority,
20});
21
22console.log('Data Item delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeDataItemV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const dataItemDelegate = publicKey('delegateAddress...');
10
11await revokeDataItemV1(umi, {
12 mint,
13 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
14 delegate: dataItemDelegate,
15 tokenStandard: TokenStandard.NonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Data Item delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeDataItemV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const dataItemDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeDataItemV1InstructionAsync({
11 mint,
12 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
13 delegate: dataItemDelegate,
14 tokenStandard: TokenStandard.NonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [revokeIx],
19 payer: updateAuthority,
20});
21
22console.log('Data Item delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsDataItemDelegateV2,
4 fetchMetadataFromSeeds,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const dataItemDelegate = umi.identity; // The delegate authority
9
10const initialMetadata = await fetchMetadataFromSeeds(umi, { mint });
11await updateAsDataItemDelegateV2(umi, {
12 mint,
13 authority: dataItemDelegate,
14 data: { ...initialMetadata, name: 'Updated Name' },
15}).sendAndConfirm(umi);
16
17console.log('Asset data updated via Data Item delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsDataItemDelegateV2InstructionAsync,
4 fetchMetadata,
5 findMetadataPda,
6} from '@metaplex-foundation/mpl-token-metadata-kit';
7
8const mint = address('mintAddress...');
9
10const [metadataAddress] = await findMetadataPda({ mint });
11const initialMetadata = await fetchMetadata(rpc, metadataAddress);
12
13const updateIx = await getUpdateAsDataItemDelegateV2InstructionAsync({
14 mint,
15 authority: dataItemDelegate,
16 data: {
17 ...initialMetadata,
18 name: 'Updated Name',
19 creators: null, // Required when passing data
20 },
21});
22
23await sendAndConfirm({
24 instructions: [updateIx],
25 payer: dataItemDelegate,
26});
27
28console.log('Asset data updated via Data Item delegate');
Programmable Config 委托
- 可编程配置委托仅适用于可编程非同质化代币。
- 委托权限可以更新元数据账户的
programmableConfigs属性,但不能更新其他内容。这意味着它可以更新 PNFT 的ruleSet。 - 当应用于集合 NFT 时,委托权限可以对该集合中的项目执行相同的更新。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateProgrammableConfigV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const programmableConfigDelegate = publicKey('delegateAddress...');
10
11await delegateProgrammableConfigV1(umi, {
12 mint,
13 authority: updateAuthority,
14 delegate: programmableConfigDelegate,
15 tokenStandard: TokenStandard.ProgrammableNonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Programmable Config delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateProgrammableConfigV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const programmableConfigDelegate = address('delegateAddress...');
9
10const delegateIx = await getDelegateProgrammableConfigV1InstructionAsync({
11 mint,
12 authority: updateAuthority,
13 delegate: programmableConfigDelegate,
14 tokenStandard: TokenStandard.ProgrammableNonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [delegateIx],
19 payer: updateAuthority,
20});
21
22console.log('Programmable Config delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeProgrammableConfigV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const programmableConfigDelegate = publicKey('delegateAddress...');
10
11await revokeProgrammableConfigV1(umi, {
12 mint,
13 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
14 delegate: programmableConfigDelegate,
15 tokenStandard: TokenStandard.ProgrammableNonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Programmable Config delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeProgrammableConfigV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const programmableConfigDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeProgrammableConfigV1InstructionAsync({
11 mint,
12 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
13 delegate: programmableConfigDelegate,
14 tokenStandard: TokenStandard.ProgrammableNonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [revokeIx],
19 payer: updateAuthority,
20});
21
22console.log('Programmable Config delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsProgrammableConfigDelegateV2,
4 ruleSetToggle,
5} from '@metaplex-foundation/mpl-token-metadata';
6import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
7
8const mint = publicKey('mintAddress...');
9const assetOwner = publicKey('ownerAddress...');
10const programmableConfigDelegate = umi.identity; // The delegate authority
11const ruleSet = publicKey('ruleSetAddress...');
12
13await updateAsProgrammableConfigDelegateV2(umi, {
14 mint,
15 token: findAssociatedTokenPda(umi, { mint, owner: assetOwner }),
16 authority: programmableConfigDelegate,
17 ruleSet: ruleSetToggle('Set', [ruleSet]),
18}).sendAndConfirm(umi);
19
20console.log('Rule set updated via Programmable Config delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsProgrammableConfigDelegateV2InstructionAsync,
4 findAssociatedTokenPda,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const assetOwner = address('ownerAddress...');
9const ruleSet = address('ruleSetAddress...');
10
11const [token] = await findAssociatedTokenPda({ mint, owner: assetOwner });
12const updateIx = await getUpdateAsProgrammableConfigDelegateV2InstructionAsync({
13 mint,
14 token,
15 authority: programmableConfigDelegate,
16 ruleSet: { __kind: 'Set', fields: [ruleSet] },
17});
18
19await sendAndConfirm({
20 instructions: [updateIx],
21 payer: programmableConfigDelegate,
22});
23
24console.log('Rule set updated via Programmable Config delegate');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsProgrammableConfigDelegateV2,
4 ruleSetToggle,
5} from '@metaplex-foundation/mpl-token-metadata';
6import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
7
8const mint = publicKey('mintAddress...'); // The collection item
9const collectionMint = publicKey('collectionMintAddress...');
10const assetOwner = publicKey('ownerAddress...');
11const programmableConfigDelegate = umi.identity; // The delegate authority
12const ruleSet = publicKey('ruleSetAddress...');
13
14await updateAsProgrammableConfigDelegateV2(umi, {
15 mint,
16 token: findAssociatedTokenPda(umi, { mint, owner: assetOwner }),
17 delegateMint: collectionMint,
18 authority: programmableConfigDelegate,
19 ruleSet: ruleSetToggle('Set', [ruleSet]),
20}).sendAndConfirm(umi);
21
22console.log('Collection item rule set updated via Programmable Config delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsProgrammableConfigDelegateV2InstructionAsync,
4 findAssociatedTokenPda,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...'); // The collection item
8const collectionMint = address('collectionMintAddress...');
9const assetOwner = address('ownerAddress...');
10const ruleSet = address('ruleSetAddress...');
11
12const [token] = await findAssociatedTokenPda({ mint, owner: assetOwner });
13const updateIx = await getUpdateAsProgrammableConfigDelegateV2InstructionAsync({
14 mint,
15 token,
16 delegateMint: collectionMint,
17 authority: programmableConfigDelegate,
18 ruleSet: { __kind: 'Set', fields: [ruleSet] },
19});
20
21await sendAndConfirm({
22 instructions: [updateIx],
23 payer: programmableConfigDelegate,
24});
25
26console.log('Collection item rule set updated via Programmable Config delegate');
Programmable Config Item 委托
- 可编程配置委托仅适用于可编程非同质化代币。
- 委托权限可以更新元数据账户的
programmableConfigs属性,但不能更新其他内容。这意味着它可以更新 PNFT 的ruleSet。 - 即使资产是集合 NFT,与可编程配置委托相反,可编程配置项委托也不能影响该集合的项目。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateProgrammableConfigItemV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const programmableConfigItemDelegate = publicKey('delegateAddress...');
10
11await delegateProgrammableConfigItemV1(umi, {
12 mint,
13 authority: updateAuthority,
14 delegate: programmableConfigItemDelegate,
15 tokenStandard: TokenStandard.ProgrammableNonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Programmable Config Item delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateProgrammableConfigItemV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const programmableConfigItemDelegate = address('delegateAddress...');
9
10const delegateIx = await getDelegateProgrammableConfigItemV1InstructionAsync({
11 mint,
12 authority: updateAuthority,
13 delegate: programmableConfigItemDelegate,
14 tokenStandard: TokenStandard.ProgrammableNonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [delegateIx],
19 payer: updateAuthority,
20});
21
22console.log('Programmable Config Item delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeProgrammableConfigItemV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const updateAuthority = umi.identity;
9const programmableConfigItemDelegate = publicKey('delegateAddress...');
10
11await revokeProgrammableConfigItemV1(umi, {
12 mint,
13 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
14 delegate: programmableConfigItemDelegate,
15 tokenStandard: TokenStandard.ProgrammableNonFungible,
16}).sendAndConfirm(umi);
17
18console.log('Programmable Config Item delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeProgrammableConfigItemV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const programmableConfigItemDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeProgrammableConfigItemV1InstructionAsync({
11 mint,
12 authority: updateAuthority, // Or pass the delegate authority as a Signer to self-revoke
13 delegate: programmableConfigItemDelegate,
14 tokenStandard: TokenStandard.ProgrammableNonFungible,
15});
16
17await sendAndConfirm({
18 instructions: [revokeIx],
19 payer: updateAuthority,
20});
21
22console.log('Programmable Config Item delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 updateAsProgrammableConfigItemDelegateV2,
4 ruleSetToggle,
5} from '@metaplex-foundation/mpl-token-metadata';
6import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
7
8const mint = publicKey('mintAddress...');
9const assetOwner = publicKey('ownerAddress...');
10const programmableConfigItemDelegate = umi.identity; // The delegate authority
11const ruleSet = publicKey('ruleSetAddress...');
12
13await updateAsProgrammableConfigItemDelegateV2(umi, {
14 mint,
15 token: findAssociatedTokenPda(umi, { mint, owner: assetOwner }),
16 authority: programmableConfigItemDelegate,
17 ruleSet: ruleSetToggle('Set', [ruleSet]),
18}).sendAndConfirm(umi);
19
20console.log('Rule set updated via Programmable Config Item delegate');
1import { address } from '@solana/addresses';
2import {
3 getUpdateAsProgrammableConfigItemDelegateV2InstructionAsync,
4 findAssociatedTokenPda,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const assetOwner = address('ownerAddress...');
9const ruleSet = address('ruleSetAddress...');
10
11const [token] = await findAssociatedTokenPda({ mint, owner: assetOwner });
12const updateIx = await getUpdateAsProgrammableConfigItemDelegateV2InstructionAsync({
13 mint,
14 token,
15 authority: programmableConfigItemDelegate,
16 ruleSet: { __kind: 'Set', fields: [ruleSet] },
17});
18
19await sendAndConfirm({
20 instructions: [updateIx],
21 payer: programmableConfigItemDelegate,
22});
23
24console.log('Rule set updated via Programmable Config Item delegate');
代币委托
代币委托是在代币级别操作的委托。这意味着它们是直接存储在 SPL Token 程序的代币账户上的 spl-token 委托。因此,代币委托允许委托代表所有者转移和销毁代币,但也可以锁定和解锁代币以防止所有者转移、销毁甚至撤销委托。这些委托对于无托管市场、质押、资产贷款等应用程序至关重要。
虽然 SPL Token 程序只提供一种类型的委托,但可编程 NFT(PNFT)允许 Token Metadata 程序提供更细粒度的委托,可以根据具体情况进行选择。这是因为 PNFT 在 SPL Token 程序上始终被冻结,这意味着我们可以在其上构建委托系统。
我们将该委托系统存储在 PNFT 特定账户上,称为代币记录 PDA——其种子为 ["metadata", program id, mint id, "token_record", token account id]。我们也在 SPL Token 程序上同步委托权限,但代币始终被冻结。代币记录账户负责跟踪资产是否真的被锁定。
以下是代币委托的一些关键属性:
- 每个代币账户只能有一个代币委托。在同一个代币账户上设置新的代币委托将覆盖现有的委托。
- 只要资产未被锁定,资产所有者就可以撤销代币委托。
- 代币委托不能自行撤销,因为它们也在代币程序上设置,而代币程序不允许委托自行撤销。
- 代币委托在转移时重置。在处理同质化资产时,当所有委托的代币都被转移时,委托权限将重置。
- 标准委托可以被除可编程非同质化代币之外的所有资产使用。所有其他代币委托只能被可编程非同质化代币使用。
- 所有可以被可编程非同质化代币使用的代币委托都会在 PNFT 的代币记录账户上存储当前的委托权限、其角色及其状态——锁定或解锁。
存在 6 种不同类型的代币委托,每种都有不同的操作范围。以下是总结不同类型代币委托的表格:
| 委托 | 锁定/解锁 | 转移 | 销毁 | 适用于 | 注意 |
|---|---|---|---|---|---|
| Standard | ✅ | ✅ | ✅ | 除 PNFT 外的所有资产 | |
| Sale | ❌ | ✅ | ❌ | 仅限 PNFT | 在撤销委托之前,所有者无法转移/销毁 |
| Transfer | ❌ | ✅ | ❌ | 仅限 PNFT | 即使设置了委托,所有者也可以转移/销毁 |
| Locked Transfer | ✅ | ✅ | ❌ | 仅限 PNFT | |
| Utility | ✅ | ❌ | ✅ | 仅限 PNFT | |
| Staking | ✅ | ❌ | ❌ | 仅限 PNFT |
请注意,标准委托比其他 PNFT 特定委托拥有更多权力,因为我们必须简单地遵从 spl-token 委托。但是,其他委托更细粒度,可以在更具体的用例中使用。例如,销售委托非常适合在市场上列出资产,因为只要设置了委托,它们就会禁止所有者销毁或转移。
让我们更详细地介绍每个代币委托,并提供批准、撤销和使用它们的代码示例。
Standard 委托
如上所述,标准委托是 spl-token 委托的包装器。虽然我们可以直接向 Token 程序发送指令,但此委托旨在在 Token Metadata 上提供相同的 API,无论代币标准如何。此外,标准委托能够锁定/解锁资产,这在原生 spl-token 委托中是不可能的。
以下是标准委托的一些关键属性:
- 此委托不适用于可编程非同质化代币。
- 委托权限可以将资产转移到任何地址。这样做将撤销委托权限。
- 委托权限可以销毁资产。
- 委托权限可以锁定资产——也称为在 Token 程序上"冻结"资产。在委托权限解锁(或"解冻")资产之前,所有者无法转移它、销毁它或撤销委托权限。这是标准委托特有的,在原生 spl-token 委托中无法完成。
- 当与同质化资产一起使用时,可以提供大于 1 的金额来指定要委托给委托权限的代币数量。
1import { delegateStandardV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and standardDelegate are set up
4
5await delegateStandardV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: standardDelegate,
10 tokenStandard: TokenStandard.NonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Standard delegate approved');
1import {
2 getDelegateStandardV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and standardDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Approve a Standard delegate
11const delegateIx = await getDelegateStandardV1InstructionAsync({
12 mint: mintAddress,
13 delegate: standardDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.NonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [delegateIx],
22 payer: owner,
23});
24
25console.log('Standard delegate approved');
1import { revokeStandardV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and standardDelegate are set up
4
5await revokeStandardV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: standardDelegate,
10 tokenStandard: TokenStandard.NonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Standard delegate revoked');
1import {
2 getRevokeStandardV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and standardDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Revoke a Standard delegate
11const revokeIx = await getRevokeStandardV1InstructionAsync({
12 mint: mintAddress,
13 delegate: standardDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.NonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [revokeIx],
22 payer: owner,
23});
24
25console.log('Standard delegate revoked');
1import { transferV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, standardDelegate, currentOwner, and newOwner are set up
4
5await transferV1(umi, {
6 mint,
7 authority: standardDelegate,
8 tokenOwner: currentOwner,
9 destinationOwner: newOwner,
10 tokenStandard: TokenStandard.NonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Asset transferred by Standard delegate');
1import {
2 getTransferV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and standardDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9const currentOwner = 'currentOwnerAddress...';
10const newOwner = 'newOwnerAddress...';
11
12// Transfer as Standard delegate
13const transferIx = await getTransferV1InstructionAsync({
14 mint: mintAddress,
15 authority: standardDelegate,
16 payer: standardDelegate,
17 tokenOwner: currentOwner,
18 destinationOwner: newOwner,
19 tokenStandard: TokenStandard.NonFungible,
20});
21
22await sendAndConfirm({
23 instructions: [transferIx],
24 payer: standardDelegate,
25});
26
27console.log('Asset transferred by Standard delegate');
1import { burnV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, standardDelegate, and currentOwner are set up
4
5await burnV1(umi, {
6 mint,
7 authority: standardDelegate,
8 tokenOwner: currentOwner,
9 tokenStandard: TokenStandard.NonFungible,
10}).sendAndConfirm(umi);
11
12console.log('Asset burned by Standard delegate');
1import {
2 getBurnV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and standardDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9const currentOwner = 'currentOwnerAddress...';
10
11// Burn as Standard delegate
12const burnIx = await getBurnV1InstructionAsync({
13 mint: mintAddress,
14 authority: standardDelegate,
15 payer: standardDelegate,
16 tokenOwner: currentOwner,
17 tokenStandard: TokenStandard.NonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [burnIx],
22 payer: standardDelegate,
23});
24
25console.log('Asset burned by Standard delegate');
1import { lockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and standardDelegate are set up
4
5await lockV1(umi, {
6 mint,
7 authority: standardDelegate,
8 tokenStandard: TokenStandard.NonFungible,
9}).sendAndConfirm(umi);
10
11console.log('Asset locked (frozen) by Standard delegate');
1import {
2 getLockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, standardDelegate, and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Lock (freeze) as Standard delegate
11const lockIx = await getLockV1InstructionAsync({
12 mint: mintAddress,
13 authority: standardDelegate,
14 payer: standardDelegate,
15 tokenOwner,
16 tokenStandard: TokenStandard.NonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [lockIx],
21 payer: standardDelegate,
22});
23
24console.log('Asset locked (frozen) by Standard delegate');
1import { unlockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and standardDelegate are set up
4
5await unlockV1(umi, {
6 mint,
7 authority: standardDelegate,
8 tokenStandard: TokenStandard.NonFungible,
9}).sendAndConfirm(umi);
10
11console.log('Asset unlocked (thawed) by Standard delegate');
1import {
2 getUnlockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, standardDelegate, and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Unlock (thaw) as Standard delegate
11const unlockIx = await getUnlockV1InstructionAsync({
12 mint: mintAddress,
13 authority: standardDelegate,
14 payer: standardDelegate,
15 tokenOwner,
16 tokenStandard: TokenStandard.NonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [unlockIx],
21 payer: standardDelegate,
22});
23
24console.log('Asset unlocked (thawed) by Standard delegate');
Sale 委托(仅限 PNFT)
- 此委托仅适用于可编程非同质化代币。
- 委托权限可以将 PNFT 转移到任何地址。这样做将撤销委托权限。
- 只要在 PNFT 上设置了销售委托,PNFT 就会进入称为
Listed的特殊代币状态。Listed代币状态是Locked代币状态的较软变体。在此期间,所有者无法转移或销毁 PNFT。但是,所有者可以随时撤销销售委托,这将删除Listed代币状态,并使 PNFT 再次可转移和可销毁。
1import { delegateSaleV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and saleDelegate are set up
4
5await delegateSaleV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: saleDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Sale delegate approved');
1import {
2 getDelegateSaleV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and saleDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Approve a Sale delegate (pNFT only)
11const delegateIx = await getDelegateSaleV1InstructionAsync({
12 mint: mintAddress,
13 delegate: saleDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [delegateIx],
22 payer: owner,
23});
24
25console.log('Sale delegate approved');
1import { revokeSaleV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and saleDelegate are set up
4
5await revokeSaleV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: saleDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Sale delegate revoked');
1import {
2 getRevokeSaleV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and saleDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Revoke a Sale delegate (pNFT only)
11const revokeIx = await getRevokeSaleV1InstructionAsync({
12 mint: mintAddress,
13 delegate: saleDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [revokeIx],
22 payer: owner,
23});
24
25console.log('Sale delegate revoked');
1import { transferV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, saleDelegate, currentOwner, and newOwner are set up
4
5await transferV1(umi, {
6 mint,
7 authority: saleDelegate,
8 tokenOwner: currentOwner,
9 destinationOwner: newOwner,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('pNFT transferred by Sale delegate');
1import {
2 getTransferV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and saleDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9const currentOwner = 'currentOwnerAddress...';
10const newOwner = 'newOwnerAddress...';
11
12// Transfer as Sale delegate (pNFT only)
13const transferIx = await getTransferV1InstructionAsync({
14 mint: mintAddress,
15 authority: saleDelegate,
16 payer: saleDelegate,
17 tokenOwner: currentOwner,
18 destinationOwner: newOwner,
19 tokenStandard: TokenStandard.ProgrammableNonFungible,
20});
21
22await sendAndConfirm({
23 instructions: [transferIx],
24 payer: saleDelegate,
25});
26
27console.log('pNFT transferred by Sale delegate');
Transfer 委托(仅限 PNFT)
- 此委托仅适用于可编程非同质化代币。
- 委托权限可以将 PNFT 转移到任何地址。这样做将撤销委托权限。
- 与销售委托相反,当设置了转移委托时,所有者仍然可以转移和销毁 PNFT。
1import { delegateTransferV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and transferDelegate are set up
4
5await delegateTransferV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: transferDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Transfer delegate approved');
1import {
2 getDelegateTransferV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and transferDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Approve a Transfer delegate (pNFT only)
11const delegateIx = await getDelegateTransferV1InstructionAsync({
12 mint: mintAddress,
13 delegate: transferDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [delegateIx],
22 payer: owner,
23});
24
25console.log('Transfer delegate approved');
1import { revokeTransferV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and transferDelegate are set up
4
5await revokeTransferV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: transferDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Transfer delegate revoked');
1import {
2 getRevokeTransferV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and transferDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Revoke a Transfer delegate (pNFT only)
11const revokeIx = await getRevokeTransferV1InstructionAsync({
12 mint: mintAddress,
13 delegate: transferDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [revokeIx],
22 payer: owner,
23});
24
25console.log('Transfer delegate revoked');
1import { transferV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, transferDelegate, currentOwner, and newOwner are set up
4
5await transferV1(umi, {
6 mint,
7 authority: transferDelegate,
8 tokenOwner: currentOwner,
9 destinationOwner: newOwner,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('pNFT transferred by Transfer delegate');
1import {
2 getTransferV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and transferDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9const currentOwner = 'currentOwnerAddress...';
10const newOwner = 'newOwnerAddress...';
11
12// Transfer as Transfer delegate (pNFT only)
13const transferIx = await getTransferV1InstructionAsync({
14 mint: mintAddress,
15 authority: transferDelegate,
16 payer: transferDelegate,
17 tokenOwner: currentOwner,
18 destinationOwner: newOwner,
19 tokenStandard: TokenStandard.ProgrammableNonFungible,
20});
21
22await sendAndConfirm({
23 instructions: [transferIx],
24 payer: transferDelegate,
25});
26
27console.log('pNFT transferred by Transfer delegate');
Locked Transfer 委托(仅限 PNFT)
- 此委托仅适用于可编程非同质化代币。
- 委托权限可以锁定 PNFT。在委托权限解锁 PNFT 之前,所有者无法转移它、销毁它或撤销委托权限。
- 委托权限可以将 PNFT 转移到任何地址。这样做将撤销委托权限,如果它被锁定,还会解锁 PNFT。
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 delegateLockedTransferV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const owner = umi.identity;
9const lockedTransferDelegate = publicKey('delegateAddress...');
10const lockedAddress = publicKey('escrowAddress...'); // Destination for locked transfers
11
12await delegateLockedTransferV1(umi, {
13 mint,
14 tokenOwner: owner.publicKey,
15 authority: owner,
16 delegate: lockedTransferDelegate,
17 lockedAddress,
18 tokenStandard: TokenStandard.ProgrammableNonFungible,
19}).sendAndConfirm(umi);
20
21console.log('Locked Transfer delegate approved');
1import { address } from '@solana/addresses';
2import {
3 getDelegateLockedTransferV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const lockedTransferDelegate = address('delegateAddress...');
9const lockedAddress = address('escrowAddress...'); // Destination for locked transfers
10
11const delegateIx = await getDelegateLockedTransferV1InstructionAsync({
12 mint,
13 tokenOwner: owner.address,
14 authority: owner,
15 delegate: lockedTransferDelegate,
16 lockedAddress,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [delegateIx],
22 payer: owner,
23});
24
25console.log('Locked Transfer delegate approved');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 revokeLockedTransferV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const owner = umi.identity;
9const lockedTransferDelegate = publicKey('delegateAddress...');
10
11await revokeLockedTransferV1(umi, {
12 mint,
13 tokenOwner: owner.publicKey,
14 authority: owner,
15 delegate: lockedTransferDelegate,
16 tokenStandard: TokenStandard.ProgrammableNonFungible,
17}).sendAndConfirm(umi);
18
19console.log('Locked Transfer delegate revoked');
1import { address } from '@solana/addresses';
2import {
3 getRevokeLockedTransferV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const lockedTransferDelegate = address('delegateAddress...');
9
10const revokeIx = await getRevokeLockedTransferV1InstructionAsync({
11 mint,
12 tokenOwner: owner.address,
13 authority: owner,
14 delegate: lockedTransferDelegate,
15 tokenStandard: TokenStandard.ProgrammableNonFungible,
16});
17
18await sendAndConfirm({
19 instructions: [revokeIx],
20 payer: owner,
21});
22
23console.log('Locked Transfer delegate revoked');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 transferV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const lockedTransferDelegate = umi.identity; // The delegate authority
9const currentOwner = publicKey('currentOwnerAddress...');
10const newOwner = publicKey('newOwnerAddress...');
11
12await transferV1(umi, {
13 mint,
14 authority: lockedTransferDelegate,
15 tokenOwner: currentOwner,
16 destinationOwner: newOwner,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18}).sendAndConfirm(umi);
19
20console.log('pNFT transferred via Locked Transfer delegate');
1import { address } from '@solana/addresses';
2import {
3 getTransferV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8const currentOwner = address('currentOwnerAddress...');
9const newOwner = address('newOwnerAddress...');
10
11const transferIx = await getTransferV1InstructionAsync({
12 mint,
13 authority: lockedTransferDelegate,
14 tokenOwner: currentOwner,
15 destinationOwner: newOwner,
16 tokenStandard: TokenStandard.ProgrammableNonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [transferIx],
21 payer: lockedTransferDelegate,
22});
23
24console.log('pNFT transferred via Locked Transfer delegate');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 lockV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const lockedTransferDelegate = umi.identity; // The delegate authority
9
10await lockV1(umi, {
11 mint,
12 authority: lockedTransferDelegate,
13 tokenStandard: TokenStandard.ProgrammableNonFungible,
14}).sendAndConfirm(umi);
15
16console.log('pNFT locked via Locked Transfer delegate');
1import { address } from '@solana/addresses';
2import {
3 getLockV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8
9const lockIx = await getLockV1InstructionAsync({
10 mint,
11 authority: lockedTransferDelegate,
12 tokenStandard: TokenStandard.ProgrammableNonFungible,
13});
14
15await sendAndConfirm({
16 instructions: [lockIx],
17 payer: lockedTransferDelegate,
18});
19
20console.log('pNFT locked via Locked Transfer delegate');
1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 unlockV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7const mint = publicKey('mintAddress...');
8const lockedTransferDelegate = umi.identity; // The delegate authority
9
10await unlockV1(umi, {
11 mint,
12 authority: lockedTransferDelegate,
13 tokenStandard: TokenStandard.ProgrammableNonFungible,
14}).sendAndConfirm(umi);
15
16console.log('pNFT unlocked via Locked Transfer delegate');
1import { address } from '@solana/addresses';
2import {
3 getUnlockV1InstructionAsync,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7const mint = address('mintAddress...');
8
9const unlockIx = await getUnlockV1InstructionAsync({
10 mint,
11 authority: lockedTransferDelegate,
12 tokenStandard: TokenStandard.ProgrammableNonFungible,
13});
14
15await sendAndConfirm({
16 instructions: [unlockIx],
17 payer: lockedTransferDelegate,
18});
19
20console.log('pNFT unlocked via Locked Transfer delegate');
Utility 委托(仅限 PNFT)
- 此委托仅适用于可编程非同质化代币。
- 委托权限可以锁定 PNFT。在委托权限解锁 PNFT 之前,所有者无法转移它、销毁它或撤销委托权限。
- 委托权限可以销毁 PNFT。
1import { delegateUtilityV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and utilityDelegate are set up
4
5await delegateUtilityV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: utilityDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Utility delegate approved');
1import {
2 getDelegateUtilityV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and utilityDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Approve a Utility delegate (pNFT only)
11const delegateIx = await getDelegateUtilityV1InstructionAsync({
12 mint: mintAddress,
13 delegate: utilityDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [delegateIx],
22 payer: owner,
23});
24
25console.log('Utility delegate approved');
1import { revokeUtilityV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and utilityDelegate are set up
4
5await revokeUtilityV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: utilityDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Utility delegate revoked');
1import {
2 getRevokeUtilityV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and utilityDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Revoke a Utility delegate (pNFT only)
11const revokeIx = await getRevokeUtilityV1InstructionAsync({
12 mint: mintAddress,
13 delegate: utilityDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [revokeIx],
22 payer: owner,
23});
24
25console.log('Utility delegate revoked');
1import { burnV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, utilityDelegate, and currentOwner are set up
4
5await burnV1(umi, {
6 mint,
7 authority: utilityDelegate,
8 tokenOwner: currentOwner,
9 tokenStandard: TokenStandard.ProgrammableNonFungible,
10}).sendAndConfirm(umi);
11
12console.log('pNFT burned by Utility delegate');
1import {
2 getBurnV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, and utilityDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9const currentOwner = 'currentOwnerAddress...';
10
11// Burn as Utility delegate (pNFT only)
12const burnIx = await getBurnV1InstructionAsync({
13 mint: mintAddress,
14 authority: utilityDelegate,
15 payer: utilityDelegate,
16 tokenOwner: currentOwner,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [burnIx],
22 payer: utilityDelegate,
23});
24
25console.log('pNFT burned by Utility delegate');
1import { lockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and utilityDelegate are set up
4
5await lockV1(umi, {
6 mint,
7 authority: utilityDelegate,
8 tokenStandard: TokenStandard.ProgrammableNonFungible,
9}).sendAndConfirm(umi);
10
11console.log('pNFT locked by Utility delegate');
1import {
2 getLockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, utilityDelegate, and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Lock as Utility delegate (pNFT only)
11const lockIx = await getLockV1InstructionAsync({
12 mint: mintAddress,
13 authority: utilityDelegate,
14 payer: utilityDelegate,
15 tokenOwner,
16 tokenStandard: TokenStandard.ProgrammableNonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [lockIx],
21 payer: utilityDelegate,
22});
23
24console.log('pNFT locked by Utility delegate');
1import { unlockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and utilityDelegate are set up
4
5await unlockV1(umi, {
6 mint,
7 authority: utilityDelegate,
8 tokenStandard: TokenStandard.ProgrammableNonFungible,
9}).sendAndConfirm(umi);
10
11console.log('pNFT unlocked by Utility delegate');
1import {
2 getUnlockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, utilityDelegate, and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Unlock as Utility delegate (pNFT only)
11const unlockIx = await getUnlockV1InstructionAsync({
12 mint: mintAddress,
13 authority: utilityDelegate,
14 payer: utilityDelegate,
15 tokenOwner,
16 tokenStandard: TokenStandard.ProgrammableNonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [unlockIx],
21 payer: utilityDelegate,
22});
23
24console.log('pNFT unlocked by Utility delegate');
Staking 委托(仅限 PNFT)
- 此委托仅适用于可编程非同质化代币。
- 委托权限可以锁定 PNFT。在委托权限解锁 PNFT 之前,所有者无法转移它、销毁它或撤销委托权限。
1import { delegateStakingV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and stakingDelegate are set up
4
5await delegateStakingV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: stakingDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Staking delegate approved');
1import {
2 getDelegateStakingV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and stakingDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Approve a Staking delegate (pNFT only)
11const delegateIx = await getDelegateStakingV1InstructionAsync({
12 mint: mintAddress,
13 delegate: stakingDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [delegateIx],
22 payer: owner,
23});
24
25console.log('Staking delegate approved');
1import { revokeStakingV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, owner, and stakingDelegate are set up
4
5await revokeStakingV1(umi, {
6 mint,
7 tokenOwner: owner.publicKey,
8 authority: owner,
9 delegate: stakingDelegate,
10 tokenStandard: TokenStandard.ProgrammableNonFungible,
11}).sendAndConfirm(umi);
12
13console.log('Staking delegate revoked');
1import {
2 getRevokeStakingV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, owner, and stakingDelegate are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Revoke a Staking delegate (pNFT only)
11const revokeIx = await getRevokeStakingV1InstructionAsync({
12 mint: mintAddress,
13 delegate: stakingDelegate,
14 authority: owner,
15 payer: owner,
16 tokenOwner: owner.address,
17 tokenStandard: TokenStandard.ProgrammableNonFungible,
18});
19
20await sendAndConfirm({
21 instructions: [revokeIx],
22 payer: owner,
23});
24
25console.log('Staking delegate revoked');
1import { lockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and stakingDelegate are set up
4
5await lockV1(umi, {
6 mint,
7 authority: stakingDelegate,
8 tokenStandard: TokenStandard.ProgrammableNonFungible,
9}).sendAndConfirm(umi);
10
11console.log('pNFT locked by Staking delegate');
1import {
2 getLockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, stakingDelegate, and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Lock as Staking delegate (pNFT only)
11const lockIx = await getLockV1InstructionAsync({
12 mint: mintAddress,
13 authority: stakingDelegate,
14 payer: stakingDelegate,
15 tokenOwner,
16 tokenStandard: TokenStandard.ProgrammableNonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [lockIx],
21 payer: stakingDelegate,
22});
23
24console.log('pNFT locked by Staking delegate');
1import { unlockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and stakingDelegate are set up
4
5await unlockV1(umi, {
6 mint,
7 authority: stakingDelegate,
8 tokenStandard: TokenStandard.ProgrammableNonFungible,
9}).sendAndConfirm(umi);
10
11console.log('pNFT unlocked by Staking delegate');
1import {
2 getUnlockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, stakingDelegate, and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The pNFT mint address
9
10// Unlock as Staking delegate (pNFT only)
11const unlockIx = await getUnlockV1InstructionAsync({
12 mint: mintAddress,
13 authority: stakingDelegate,
14 payer: stakingDelegate,
15 tokenOwner,
16 tokenStandard: TokenStandard.ProgrammableNonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [unlockIx],
21 payer: stakingDelegate,
22});
23
24console.log('pNFT unlocked by Staking delegate');
旧版委托
最后,值得注意的是——在这个委托系统之前——集合委托曾经存储在特定的集合权限记录 PDA 上。该 PDA 类似于元数据委托记录,不同之处在于它只支持一个角色:集合。这个旧版集合委托现已弃用,我们建议改用新的委托系统。
话虽如此,Token Metadata 程序仍然接受这些旧版集合委托,无论在哪里需要新的集合委托。这样做是为了确保与仍然委托给这些旧版委托的资产向后兼容。
您可以直接在 Token Metadata 程序中了解更多关于它们的信息。
