I'm working on project where i need to transfer NFT's or tokens from connected wallet with Phantom or Solflare. So idk how to create token account (if it doesn't exist) and include it in createTransferCheckedInstruction.

I need to do it all in one transaction and sign it with Phantom.

1 Answer 1


Great question. Here are the params args:

 * @param connection     Connection to use
 * @param payer          Payer of the transaction fees
 * @param source         Source account
 * @param mint           Mint for the account
 * @param destination    Destination account
 * @param owner          Owner of the source account
 * @param amount         Number of tokens to transfer
 * @param decimals       Number of decimals in transfer amount
 * @param multiSigners   Signing accounts if `owner` is a multisig
 * @param confirmOptions Options for confirming the transaction
 * @param programId      SPL Token program account

Sounds like you need help figuring out how to create the destination account. This account is a token account that will be:

  • owned by the SPL token program,
  • have an authority that is user you are sending to, and
  • be for the token mint of the token you are sending

To initialize the account before sending, you should use getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotent like so:

const destination = await getOrCreateAssociatedTokenAccount(
   payer, // presumably your wallet
   mint,  // of the token you are sending
   owner, // person you are sending the token to

This guide may be useful to learn a little more about how token transfers work and see a full example.

  • Thanks. By the way param payer should be window.solana if i connected with Phatnom or it should be just publickey(adress) ? And if the account doesn't exist, in order to create it you have to do the transaction first for create or it receiving with RPC? Cause I need to transfer so many NFT's from one account to another in one transaction Commented Feb 1 at 14:06
  • You might try the Solana wallet adapter instead of just Phantom Connect. And then I'd probably look at assembling transactions using the helper functions that return instructions (and then adding them together), e.g.: - createAssociatedTokenAccountIdempotentInstruction - createTransferCheckedInstruction These will return TransactionInstruction objects that you can do something like: js const transaction = new Transaction().add(ix1,ix2, ...); const signature = await sendTransaction(transaction, connection);
    – AMilz
    Commented Feb 1 at 15:35
  • Thanks. It's smart. But in the createAssociatedTokenAccountIdempotentInstruction i need the param associatedToken. Ignore him? Or it will be created during the execution of the instruction? And then, as far as I understand, in the createTransferCheckedInstruction add this 'associatedToken' or the instruction itself? Commented Feb 1 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.