3

I am trying to use the "createInitializeMintInstruction()" using JS to create a token. The problem is when executing, it throws an error. Concretely this one:

Transaction simulation failed: Error processing Instruction 1: invalid account data for instruction

  logs: [
    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
    'Program log: Instruction: InitializeMint',
    'Program log: Error: InvalidAccountData',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1547 of 399850 compute units',
    'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction'
  ]
}

The function createInitializeMintInstruction() asks for the following parameters:

@parameter mint, @parameter decimals, @parameter mintAuthority, @parameter freezeAuthority (optional) and the token program @parameter programId.

Before calling the createInitializeMintInstruction(), I create an account that will be the mint for the token using the following instruction: SystemProgram.createAccount() (using the TOKEN_PROGRAM_ID as well when creating the account).

The account is created succesfully and I pass the parameters correctly to the initializeMint instruction. I don't see why the invalid account data.

By the way, I'm using TOKEN_PROGRAM_ID from @solana/spl-token

Any help is appreciated, thank you.

2

2 Answers 2

3

Here's how I'm creating spl token with Token Program, which works for me.

const { connection } = useConnection();
const { publicKey, sendTransaction } = useWallet();
const lamports = await getMinimumBalanceForRentExemptMint(connection);
const mintKeypair = Keypair.generate();

const createNewTokenTransaction = new Transaction().add(
  SystemProgram.createAccount({
    fromPubkey: publicKey,
    newAccountPubkey: mintKeypair.publicKey,
    space: MINT_SIZE,
    lamports: lamports,
    programId: TOKEN_PROGRAM_ID,
  }),
  createInitializeMintInstruction(
    mintKeypair.publicKey,
    tokenDecimals,
    publicKey,
    publicKey,
    TOKEN_PROGRAM_ID),
);
await sendTransaction(createNewTokenTransaction, connection, { signers: [mintKeypair] });
1

It finally worked.

I checked several times but I didn't notice that the initializeMintInstruction was asking for a publickey, and I was actually passing a full keypair by mistake.

Thanks for the code though!!

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.