My Token.createMintToInstruction is throwing "Error processing instruction 0: invalid account data for instruction"

4.7k views Asked by At

I'm trying to mint some tokens on the frontend like this:

let transaction = new Transaction();
let mintToInstruction = Token.createMintToInstruction(
   splToken.TOKEN_PROGRAM_ID,
   myTokenMint.publicKey,
   userAccount.publicKey,
   airdropAdmin.publicKey,
   [],
   sendAmount.toNumber()
)

transaction.add(mintToInstruction);
       
let conn: Connection = ctx.connection;
const tx1 = await conn.sendTransaction(
  transaction,
  [airdropAdmin]
);

But I get an obscure error:

Error processing Instruction 0: invalid account data for instruction

What's happening?

1

There are 1 answers

1
Evan Conrad On

One of the accounts you're passing in is not the account the Token Program expected.

Either:

  • The userAccount is incorrect. This must be a Token Account, did you use the user's System Account instead?
  • The myMintAccount is incorrect. Is this a real token mint?

Consider logging those public keys and putting them into the explorer. Does the userAccount say "Token Account" at the top? Does the myMintAccount say "Token Mint"?

The invalid account data for instruction typically happens when a program can't run unpack on the data inside the account you're passing in.

So either the Account::unpack is failing, or the the Mint::unpack is failing.