Here's a part of the code of minting my Token-2022 which I've deployed previously
//........................
console.log(
`\npayer: ${payer} $$ ${payer.publicKey}`,
`\nmint: ${mint}`,
`\nsourceTokenAccount: ${sourceTokenAccount}`,
`\nmintAuthority: ${mintAuthority} $$ ${mintAuthority.publicKey}`,
)
transactionSignature = await mintTo(
connection,
payer, // Transaction fee payer
mint, // Mint Account address
sourceTokenAccount, // Mint to
mintAuthority, // Mint Authority address
1_000_000_000, // Amount
[], // Additional signers
undefined, // Confirmation options
TOKEN_2022_PROGRAM_ID, // Token Extension Program ID
);
//Baaaaaaaaaaaaaaaaaaaaaaaaaaaam!!!!
console.log(
"\nMint Tokens:",
`https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana`,
);
Error:
payer: [object Object] $$ 6RzpGSb4cMRN6h46DVZ5czWRQsuPGCZdmhHdhUkAYQwU
mint: EM1Y7YUqvH3Rjsi49wtxsi2R8vmzqaKbWY9PWK8JVBGY
sourceTokenAccount: DvbiZQjwtBuEwAG2WAXaf6XoCYUN9zn7Ad7iRhfHVbGU
mintAuthority: [object Object] $$ 4B8dYh439ziBUUWANjGLtAfYeZcwQ7RDEUkNY3qmHZPU
4101 | }
4102 | }
4103 |
4104 | class SendTransactionError extends Error {
4105 | constructor(message, logs) {
4106 | super(message);
^
error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction
at new SendTransactionError (..../p1/node_modules/@solana/web3.js/lib/index.cjs.js:4106:5)
at ..../p1/node_modules/@solana/web3.js/lib/index.cjs.js:8031:13
Payer has some SOL https://solscan.io/account/4B8dYh439ziBUUWANjGLtAfYeZcwQ7RDEUkNY3qmHZPU?cluster=devnet
as sourceTokenAccount
and mintAuthority
do too. And you can check them out on solscan too.
Why the error? What's wrong with the arguments?
update
const owner = Keypair.generate();
sourceTokenAccount = await createAccount(
connection,
payer, // Payer to create Token Account
mint, // Mint Account address
owner.publicKey, // Token Account owner
undefined, // Optional keypair, default to Associated Token Account
undefined, // Confirmation options
TOKEN_2022_PROGRAM_ID, // Token Extension Program ID
);
At https://spl.solana.com/token-2022/extensions#setup there's no clue that it has to be a token account.