initializeMint InvalidAccountData invalid account data for instruction
Opened this issue · 4 comments
When I created the token, I got an error message. The error message is as follows:
Program log: Instruction: InitializeMint, Program log: Error: InvalidAccountData, Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1576 of 399850 compute units, Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction
Here is my code:
Account mintAccount = new Account();
TransactionInstruction createAccount = SystemProgram.createAccount(payerAccount.getPublicKey(),mintAccount.getPublicKey(), lamports, 338, TokenProgram.PROGRAM_ID);
TransactionInstruction initializeMint = TokenProgram.initializeMint(mintAccount.getPublicKey(), 9, contractManage, contractManage);
I believe Token Mints should be created with size 82
, not 338
. See if that works.
I believe Token Mints should be created with size
82
, not338
. See if that works.
Thank you very much, I changed it to 82 and solved the problem.
May I ask how to calculate this space in Java?
Which version are you using? Latest version 1.19.2 cannot be onchain.
I submit a transaction for SystemProgram.createAccount and TokenProgram.initialiseMint's Instruction, the submission is successful and the Transaction Signature is returned,but the Transaction Signature is never found on the chain.
Please give me some help about this.
@Test
void testCreateAccount() throws Exception {
Account payer =testAccount;
System.out.println("payer: " + payer.getPublicKey());
Account mintKeypair = new Account();
PublicKey mintPubkey = mintKeypair.getPublicKey();
System.out.println("mintPubkey: " + mintPubkey.toString());
// 82
long lamports = 1461600;
long space = 82;
// create mint
TransactionInstruction createMintAccountInstruction = SystemProgram.createAccount(
payer.getPublicKey(),
mintPubkey,
lamports,
space,
TokenProgram.PROGRAM_ID
// PublicKey.valueOf("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
// PublicKey.valueOf("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
);
// init mint
TransactionInstruction initializeMintInstruction = TokenProgram.initializeMint(
mintPubkey,
9,
payer.getPublicKey(),
payer.getPublicKey()
);
TransactionInstruction initializeAccount = TokenProgram.initializeAccount(mintPubkey, payer.getPublicKey(), payer.getPublicKey());
Transaction transaction = new Transaction();
LatestBlockhash latestBlockhash = client.getApi().getLatestBlockhash();
System.out.println("latestBlockhash-->" + latestBlockhash);
String recentBlockHash = latestBlockhash.getValue().getBlockhash();
System.out.println("recentBlockHash-->" + recentBlockHash);
ArrayList<Account> accounts = new ArrayList<>();
accounts.add(payer);
accounts.add(mintKeypair);
// add
transaction.addInstruction(createMintAccountInstruction);
transaction.addInstruction(initializeMintInstruction);
// transaction.addInstruction(initializeAccount);
String res = client.getApi().sendTransaction(transaction, accounts, recentBlockHash, new RpcSendTransactionConfig());
System.out.println("Transaction Signature: " +res);
}