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:
userAccountis incorrect. This must be a Token Account, did you use the user's System Account instead?myMintAccountis incorrect. Is this a real token mint?Consider logging those public keys and putting them into the explorer. Does the
userAccountsay "Token Account" at the top? Does themyMintAccountsay "Token Mint"?The
invalid account data for instructiontypically happens when a program can't rununpackon the data inside the account you're passing in.So either the
Account::unpackis failing, or the theMint::unpackis failing.