기능

자산 전송

자산의 소유자는 Token Metadata 프로그램에 Transfer 명령어를 보내 자산을 다른 계정으로 전송할 수 있습니다. 이 명령어는 다음 속성을 받습니다:

  • Authority: 전송을 승인하는 서명자. 일반적으로 이는 자산의 소유자이지만 "위임된 권한" 페이지에서 논의된 바와 같이 특정 위임된 권한도 소유자를 대신하여 자산을 전송할 수 있다는 점에 주목하세요.
  • Token Owner: 자산의 현재 소유자의 공개 키.
  • Destination Owner: 자산의 새 소유자의 공개 키.
  • Token Standard: 전송되는 자산의 표준. 이 명령어는 자산 전송을 위한 통합된 인터페이스를 제공하기 위해 모든 토큰 표준에서 작동합니다. 하지만 프로그래머블이 아닌 자산은 SPL Token 프로그램의 Transfer 명령어를 직접 사용하여 전송할 수 있다는 점에 주목할 가치가 있습니다.

다음은 Token Metadata에서 자산을 전송하기 위해 우리의 SDK를 사용하는 방법입니다.

NFT 전송

1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 transferV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7// Assuming umi is set up with mplTokenMetadata plugin
8// See getting-started for full setup
9
10const mintAddress = publicKey('mintAddress...');
11const currentOwner = umi.identity; // Current token owner
12const destinationOwner = publicKey('destinationWallet...');
13
14// Transfer the NFT to a new owner
15await transferV1(umi, {
16 mint: mintAddress,
17 authority: currentOwner,
18 tokenOwner: currentOwner.publicKey,
19 destinationOwner,
20 tokenStandard: TokenStandard.NonFungible,
21}).sendAndConfirm(umi);
22
23console.log('NFT transferred to:', destinationOwner);

pNFT 전송

프로그래머블 NFT(pNFT)는 전송 중에 처리해야 하는 추가 인증 규칙을 가질 수 있습니다. 명령어는 자동으로 Token Record 계정을 처리합니다.

1import { publicKey } from '@metaplex-foundation/umi';
2import {
3 transferV1,
4 TokenStandard,
5} from '@metaplex-foundation/mpl-token-metadata';
6
7// Assuming umi is set up with mplTokenMetadata plugin
8
9const mintAddress = publicKey('mintAddress...');
10const currentOwner = umi.identity;
11const destinationOwner = publicKey('destinationWallet...');
12
13// Transfer the Programmable NFT to a new owner
14// Note: pNFTs require additional Token Record accounts handled automatically
15await transferV1(umi, {
16 mint: mintAddress,
17 authority: currentOwner,
18 tokenOwner: currentOwner.publicKey,
19 destinationOwner,
20 tokenStandard: TokenStandard.ProgrammableNonFungible,
21}).sendAndConfirm(umi);
22
23console.log('pNFT transferred to:', destinationOwner);

고급 pNFT 전송

복잡한 인증 규칙을 가진 pNFT의 경우 추가 매개변수를 제공해야 할 수 있습니다.

1import { getMplTokenAuthRulesProgramId } from '@metaplex-foundation/mpl-candy-machine';
2import {
3 fetchDigitalAssetWithAssociatedToken,
4 findTokenRecordPda,
5 TokenStandard,
6 transferV1,
7} from '@metaplex-foundation/mpl-token-metadata';
8import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
9import { publicKey, unwrapOptionRecursively } from '@metaplex-foundation/umi';
10import { base58 } from '@metaplex-foundation/umi/serializers';
11
12// The NFT Asset Mint ID
13const mintId = publicKey('11111111111111111111111111111111');
14
15// The destination wallet
16const destinationAddress = publicKey('22222222222222222222222222222222');
17
18// Fetch the pNFT Asset with the Token Account
19const assetWithToken = await fetchDigitalAssetWithAssociatedToken(
20 umi,
21 mintId,
22 umi.identity.publicKey
23);
24
25// Calculates the destination wallet's Token Account
26const destinationTokenAccount = findAssociatedTokenPda(umi, {
27 mint: mintId,
28 owner: destinationAddress,
29});
30
31// Calculates the destinations wallet's Token Record Account
32const destinationTokenRecord = findTokenRecordPda(umi, {
33 mint: mintId,
34 token: destinationTokenAccount[0],
35});
36
37// Transfer the pNFT
38const { signature } = await transferV1(umi, {
39 mint: mintId,
40 destinationOwner: destinationAddress,
41 destinationTokenRecord: destinationTokenRecord,
42 tokenRecord: assetWithToken.tokenRecord?.publicKey,
43 tokenStandard: TokenStandard.ProgrammableNonFungible,
44 // Check to see if the pNFT asset as auth rules.
45 authorizationRules:
46 unwrapOptionRecursively(assetWithToken.metadata.programmableConfig)
47 ?.ruleSet || undefined,
48 // Auth rules program ID
49 authorizationRulesProgram: getMplTokenAuthRulesProgramId(umi),
50 // Some pNFTs may require authorization data if set.
51 authorizationData: undefined,
52}).sendAndConfirm(umi);
53
54console.log('Signature:', base58.deserialize(signature));