0

I want to make a transfer from my wallet to another wallet with code. I use web3.js and I made a Solana transfer, but I don't know how to make an NFT transfer.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
VovaProg
  • 19
  • 2

2 Answers2

1

NFTs on Solana are represented as SPL tokens, which can be transferred in JS using the "@solana/spl-token" package on npm: https://www.npmjs.com/package/@solana/spl-token

There's an example of how to use it at https://github.com/solana-labs/solana-program-library/blob/master/token/js/examples/createMintAndTransferTokens.ts and in the repo tests.

You can find more information on SPL tokens at https://spl.solana.com/token

Jon C
  • 7,019
  • 10
  • 17
  • `create_mint_and_transfer_tokens.js` has been deleted. Would https://spl.solana.com/token#example-transferring-tokens-to-another-user be a better example? – mikemaccana Aug 24 '22 at 17:20
  • 1
    Sorry, the file name change, so I updated the link. And both examples are fine to use! – Jon C Aug 25 '22 at 18:10
0

NFT transfer is same as normal spl-token transfer. Prior to transfer NFT, you need to know its Token Mint Address or its Associated Token Account of yours. Also need to know receiver's Associated Token Account of NFT Mint Token Account. If receiver doesn't have associated token account, you or he need to create it first. If you are not familiar with the account types, please read my article on medium. https://medium.com/@blockchainlover2019/how-to-verify-ownership-of-metaplex-nft-programmatically-at-on-chain-1059418c3c6

Transferring token by using web3 is easy and not knowhow knowledge. This is my code from Solana program (smart contract), which transfers nft from one to another.

    let transfer_ix = spl_token::instruction::transfer(
        token_program.key,
        nft_account_to_send.key,
        nft_account_to_receive.key,
        &pda,
        &[],
        1
    )?;
    invoke_signed(
        &transfer_ix,
        &[
            nft_account_to_send.clone(),
            nft_account_to_receive.clone(),
            pda_account.clone(),
            token_program.clone(),
        ],
        &[&[&b"nft_transfer_is_easy"[..], &[_nonce]]]
    )?;

I will add another code for you, which runs on web3.

Phoon Anan
  • 49
  • 1
  • 7
  • Please be sure to review [Stack Overflow's self-promotion rules](https://stackoverflow.com/help/promotion) before linking to your own content. – Jeremy Caney Nov 11 '21 at 00:14
  • Sorry. sir. I am a newbie here. I won't repeat such things. – Phoon Anan Nov 11 '21 at 06:53
  • No problem. For now, however, please be sure to at least edit your answer to acknowledge that it’s your article. You want to be careful linking to your content, but if you must, you definitely want to acknowledge it is yours. – Jeremy Caney Nov 11 '21 at 16:53
  • @PhoonANan could you please explain what are the arguments passed to these functions, as it's not clearly understandable by a beginner (or at least, could you give a link to a documentation where the signatures of `transfer` and `invoke_signed` are explained in details). Thank you. – Royal Bg Dec 01 '21 at 20:17
  • This code is in Rust, JS code was never added, and the Medium article no longer exists. – mikemaccana Aug 24 '22 at 17:25