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?
One of the accounts you're passing in is not the account the Token Program expected.
Either:
userAccount
is incorrect. This must be a Token Account, did you use the user's System Account instead?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 themyMintAccount
say "Token Mint"?The
invalid account data for instruction
typically happens when a program can't rununpack
on the data inside the account you're passing in.So either the
Account::unpack
is failing, or the theMint::unpack
is failing.