機能
アセットのロック
「委任された権限」ページで述べられているように、特定の委任はアセットをロックおよびロック解除でき、所有者がそれらを転送またはバーンすることを防ぐことができます。ロックされたアセットはまた、所有者が委任の権限を取り消すことも禁止します。このロック機能により、エスクローアカウントなしでは機能しない様々なユーティリティの使用例(ステーキングなど)が可能になります。
以下の表で、アセットのロックをサポートするすべてのToken委任をリストします。これらの各委任の詳細と、それらを承認/取り消す方法については、それぞれのセクションで学ぶことができます。
| 委任 | ロック/ロック解除 | 転送 | バーン | 対象 |
|---|---|---|---|---|
| Standard | ✅ | ✅ | ✅ | pNFT以外すべて |
| Locked Transfer | ✅ | ✅ | ❌ | pNFTのみ |
| Utility | ✅ | ❌ | ✅ | pNFTのみ |
| Staking | ✅ | ❌ | ❌ | pNFTのみ |
アセットに承認されたToken委任があると仮定して、委任がそれをロックおよびロック解除する方法を見てみましょう。
アセットのロック
NFT
アセットをロックするには、委任がToken MetadataプログラムのLock命令を使用できます。この命令は以下の属性を受け取ります:
- Mint: アセットのMintアカウントのアドレス。
- Authority: ロックを承認する署名者。これは委任された権限である必要があります。
- Token Standard: ロックされるアセットの標準。Token Metadataプログラムは明示的にこの引数を必要としませんが、SDKが他のほとんどのパラメーターに適切なデフォルト値を提供できるようにするために必要です。
1import { lockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and authority (delegate) are set up
4
5await lockV1(umi, {
6 mint,
7 authority,
8 tokenStandard: TokenStandard.NonFungible,
9}).sendAndConfirm(umi);
10
11console.log('NFT locked');
1import {
2 getLockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, authority (delegate), and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Lock an NFT (freeze) - requires approved delegate authority
11const lockIx = await getLockV1InstructionAsync({
12 mint: mintAddress,
13 authority,
14 payer: authority,
15 tokenOwner,
16 tokenStandard: TokenStandard.NonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [lockIx],
21 payer: authority,
22});
23
24console.log('NFT locked');
pNFT
1import {
2 fetchDigitalAssetWithAssociatedToken,
3 lockV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6import { publicKey } from '@metaplex-foundation/umi';
7import { base58 } from '@metaplex-foundation/umi/serializers';
8
9// Assuming umi is set up with mplTokenMetadata plugin
10
11// Mint ID of the pNFT Asset
12const mintId = publicKey('11111111111111111111111111111111');
13
14// Fetch pNFT Asset with Token Accounts
15const assetWithToken = await fetchDigitalAssetWithAssociatedToken(
16 umi,
17 mintId,
18 umi.identity.publicKey
19);
20
21// Send lock instruction
22const { signature } = await lockV1(umi, {
23 // Mint ID of the pNFT Asset
24 mint: mintId,
25 // Update Authority or Delegate Authority
26 authority: umi.identity,
27 // Token Standard
28 tokenStandard: TokenStandard.ProgrammableNonFungible,
29 // Owner of the pNFT Asset
30 tokenOwner: assetWithToken.token.owner,
31 // Token Account of the pNFT Asset
32 token: assetWithToken.token.publicKey,
33 // Token Record of the pNFT Asset
34 tokenRecord: assetWithToken.tokenRecord?.publicKey,
35}).sendAndConfirm(umi);
36
37console.log('Signature: ', base58.deserialize(signature));
1import {
2 getLockV1InstructionAsync,
3 fetchDigitalAssetWithAssociatedToken,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7// Assuming rpc, rpcSubscriptions, sendAndConfirm, and authority (delegate) are set up
8
9const mintAddress = 'mintAddress...'; // The pNFT mint address
10
11// Fetch pNFT Asset with Token Accounts
12const assetWithToken = await fetchDigitalAssetWithAssociatedToken(
13 rpc,
14 mintAddress,
15 authority.address
16);
17
18// Lock a pNFT - requires approved delegate authority
19const lockIx = await getLockV1InstructionAsync({
20 mint: mintAddress,
21 authority,
22 payer: authority,
23 tokenOwner: assetWithToken.token.owner,
24 token: assetWithToken.token.address,
25 tokenRecord: assetWithToken.tokenRecord?.address,
26 tokenStandard: TokenStandard.ProgrammableNonFungible,
27});
28
29await sendAndConfirm({
30 instructions: [lockIx],
31 payer: authority,
32});
33
34console.log('pNFT locked');
アセットのロック解除
NFT
相互に、委任はToken MetadataプログラムのUnlock命令を使用してアセットをロック解除できます。この命令はLock命令と同じ属性を受け取り、同じ方法で使用できます。
1import { unlockV1 } from '@metaplex-foundation/mpl-token-metadata';
2
3// Assuming umi, mint, and authority (delegate) are set up
4
5await unlockV1(umi, {
6 mint,
7 authority,
8 tokenStandard: TokenStandard.NonFungible,
9}).sendAndConfirm(umi);
10
11console.log('NFT unlocked');
1import {
2 getUnlockV1InstructionAsync,
3 TokenStandard,
4} from '@metaplex-foundation/mpl-token-metadata-kit';
5
6// Assuming rpc, rpcSubscriptions, sendAndConfirm, authority (delegate), and tokenOwner are set up
7
8const mintAddress = 'mintAddress...'; // The NFT mint address
9
10// Unlock an NFT (thaw) - requires approved delegate authority
11const unlockIx = await getUnlockV1InstructionAsync({
12 mint: mintAddress,
13 authority,
14 payer: authority,
15 tokenOwner,
16 tokenStandard: TokenStandard.NonFungible,
17});
18
19await sendAndConfirm({
20 instructions: [unlockIx],
21 payer: authority,
22});
23
24console.log('NFT unlocked');
pNFT
1import {
2 fetchDigitalAssetWithAssociatedToken,
3 TokenStandard,
4 unlockV1,
5} from '@metaplex-foundation/mpl-token-metadata';
6import { publicKey } from '@metaplex-foundation/umi';
7import { base58 } from '@metaplex-foundation/umi/serializers';
8
9// Assuming umi is set up with mplTokenMetadata plugin
10
11// Mint pNFT ID of the Asset
12const mintId = publicKey('11111111111111111111111111111111');
13
14// Fetch the mint token accounts
15const assetWithToken = await fetchDigitalAssetWithAssociatedToken(
16 umi,
17 mintId,
18 umi.identity.publicKey
19);
20
21// Send unlock instruction
22const { signature } = await unlockV1(umi, {
23 // Mint ID of the pNFT Asset
24 mint: mintId,
25 // Update Authority or Delegate Authority
26 authority: umi.identity,
27 // Token Standard
28 tokenStandard: TokenStandard.ProgrammableNonFungible,
29 // Owner of the pNFT Assets
30 tokenOwner: assetWithToken.token.owner,
31 // Token Account of the pNFT Asset
32 token: assetWithToken.token.publicKey,
33 // Token Record of the pNFT Asset
34 tokenRecord: assetWithToken.tokenRecord?.publicKey,
35}).sendAndConfirm(umi);
36
37console.log('Signature: ', base58.deserialize(signature));
1import {
2 getUnlockV1InstructionAsync,
3 fetchDigitalAssetWithAssociatedToken,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata-kit';
6
7// Assuming rpc, rpcSubscriptions, sendAndConfirm, and authority (delegate) are set up
8
9const mintAddress = 'mintAddress...'; // The pNFT mint address
10
11// Fetch pNFT Asset with Token Accounts
12const assetWithToken = await fetchDigitalAssetWithAssociatedToken(
13 rpc,
14 mintAddress,
15 authority.address
16);
17
18// Unlock a pNFT - requires approved delegate authority
19const unlockIx = await getUnlockV1InstructionAsync({
20 mint: mintAddress,
21 authority,
22 payer: authority,
23 tokenOwner: assetWithToken.token.owner,
24 token: assetWithToken.token.address,
25 tokenRecord: assetWithToken.tokenRecord?.address,
26 tokenStandard: TokenStandard.ProgrammableNonFungible,
27});
28
29await sendAndConfirm({
30 instructions: [unlockIx],
31 payer: authority,
32});
33
34console.log('pNFT unlocked');
