0

I'm trying to write instructions for transferring spl-tokens(not nft):

const transfer = createTransferCheckedInstruction(
    account_from.publicKey,
    mintId,
    account_desc.publicKey,
    account_from.publicKey,
    1,
    8
  )

Error log:

'Program log: Instruction: TransferChecked',
    'Program log: Error: InvalidAccountData',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1357 of 599700 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction'

What am I doing wrong ?

P.S.: may be account_from.publicKey and account_from.publicKey should be associated token account keys ? but i get error again.

4

1 Answer 1

2

It looks like the issue is that you're using the account_from.publicKey as the source token account owner

const transfer = createTransferCheckedInstruction(
    account_from.publicKey,
    mintId,
    account_desc.publicKey,
    account_from.publicKey, // this should be owner of `acount_from` token account
    1,
    8
  )

Here is a Solana Playground link you can reference.

Specifically here:

// Create transferChecked instruction
const instruction = createTransferCheckedInstruction(
  sourceTokenAccount.address, // source token account
  mint, // mint address
  destinationTokenAccount.address, // destination token account
  wallet_1.publicKey, // source token account owner
  100, // amount (1 token)
  2 // decimals of mint
);

// Create new transaction and add instruction
const transaction = new Transaction().add(instruction);

// Send transaction
const transactionSignature3 = await sendAndConfirmTransaction(
  connection,
  transaction,
  [wallet_1.keypair] // signer
);
0

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.