I have a problem with sending tokens. I need to send NFT from my Phantom wallet. Most likely the problem is with Assosiated Token Account
, because somewhere in this process I catch errors. I'm trying to create an instruction for ATA
, and add it to the transaction before executing the instruction to transfer the tokens (NFT)
Errors like this: Error processing Instruction 2: Provided seeds do not result in a valid address
let receiverATA = await getAssociatedTokenAddress(mintAddress, receiverPublicKey);
const destination = await createAssociatedTokenAccountIdempotentInstruction(
window.solana.publicKey, // presumably your wallet
receiverATA,
mintAddress, // of the token you are sending
receiverPublicKey, // person you are sending the token to
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID
);
transaction.add(destination);
console.log("destination:", destination);
await sleep(350);
if (amount > 0) {
const transferInstruction = createTransferInstruction(
senderTokenAccountAddress,
receiverATA,
senderPublicKey,
amount * Math.pow(10, decimals),
[],
TOKEN_PROGRAM_ID
);
transaction.add(transferInstruction);
await sleep(300);
}
}
transaction.feePayer = window.solana.publicKey;
let blockhashObj = await connection.getRecentBlockhash();
transaction.recentBlockhash = await blockhashObj.blockhash;
const signed = await window.solana.signTransaction(transaction);
let txid = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(txid);