Amir Alam
Amir Alam

Reputation: 313

How to transfer NFT spl-token using phantom wallet and solana web3js

I can transfer the Solana from one account to another account using phantom wallet using this code

const transferTransaction = new Transaction()
  .add(SystemProgram.transfer({
    fromPubkey: alice.publicKey,
    toPubkey: feePayer.publicKey,
    lamports: lamportsToSend
  }))
  
  const network = "https://api.devnet.solana.com";
const connection = new Connection(network);
transferTransaction.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;
transferTransaction.feePayer = alice.publicKey;
const { signature } = await window.solana.signAndSendTransaction(transferTransaction);
await connection.confirmTransaction(signature);

  console.log(signature);

but I am wondering how can I transfer the NFT if I have the nft minted address?

Upvotes: 3

Views: 3676

Answers (1)

Jon C
Jon C

Reputation: 8402

To transfer an NFT, you first need to find out the address of the NFT's mint and the owner's address. Then instead of calling SystemProgram.transfer, you'll use Token.createTransferCheckedInstruction.

There's a great example at the Solana Cookbook for transferring SPL tokens: https://solanacookbook.com/references/token.html#transfer-token

Upvotes: 2

Related Questions