기능
자산 잠금
"위임된 권한" 페이지에서 언급했듯이, 특정 위임자는 자산을 잠그고 잠금 해제할 수 있어 소유자가 자산을 전송하거나 소각하는 것을 방지할 수 있습니다. 잠긴 자산은 또한 소유자가 위임자의 권한을 취소하는 것을 금지합니다. 이 잠금 메커니즘은 에스크로 계정 없이는 작동할 수 없는 스테이킹과 같은 다양한 유틸리티 사용 사례를 가능하게 합니다.
아래 표에서는 자산 잠금을 지원하는 모든 토큰 위임자를 나열합니다. 이러한 각 위임자에 대해 자세히 알아보고 승인/취소하는 방법은 해당 섹션에서 확인할 수 있습니다.
| 위임자 | 잠금/잠금 해제 | 전송 | 소각 | 대상 |
|---|---|---|---|---|
| Standard | ✅ | ✅ | ✅ | pNFT를 제외한 모든 것 |
| Locked Transfer | ✅ | ✅ | ❌ | pNFT만 |
| Utility | ✅ | ❌ | ✅ | pNFT만 |
| Staking | ✅ | ❌ | ❌ | pNFT만 |
자산에 승인된 토큰 위임자가 있다고 가정하고, 이제 위임자가 자산을 잠그고 잠금 해제하는 방법을 살펴보겠습니다.
자산 잠금
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');
