1

I've successfully implemented the minting function. After it, I added the method to create a metadata account. However, after I call the function, I get an error:

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing
  at Connection.sendEncodedTransaction (node_modules/@solana/web3.js/src/connection.ts:4480:13)
  at processTicksAndRejections (internal/process/task_queues.js:95:5)
  at Connection.sendRawTransaction (node_modules/@solana/web3.js/src/connection.ts:4439:20)
  at sendAndConfirmRawTransaction (node_modules/@project-serum/anchor/src/provider.ts:284:21)
  at AnchorProvider.sendAndConfirm (node_modules/@project-serum/anchor/src/provider.ts:144:14)
  at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:29:16)

The method itself looks like this:

invoke(
        &token_instruction::create_metadata_accounts_v2(
            ctx.accounts.token_metadata_program.key(), 
            ctx.accounts.metadata.key(), 
            ctx.accounts.mint.key(), 
            ctx.accounts.authority.key(), 
            ctx.accounts.authority.key(), 
            ctx.accounts.authority.key(), 
            metadata_title, 
            metadata_symbol, 
            metadata_uri, 
            None,
            0,
            true, 
            false, 
            None, 
            None,
        ),
        &[
            ctx.accounts.token_metadata_program.to_account_info(),
            ctx.accounts.metadata.to_account_info(),
            ctx.accounts.token_program.to_account_info(),
            ctx.accounts.mint.to_account_info(),
            ctx.accounts.token_account.to_account_info(),
            ctx.accounts.authority.to_account_info(),
        ],
    )?;

And my struct is this:

#[derive(Accounts)]
pub struct MintToken<'info> {
    /// CHECK: We're about to create this with Metaplex
    #[account(mut)]
    pub metadata: UncheckedAccount<'info>,
    /// CHECK: This is the token that we want to mint
    #[account(mut)]
    pub mint: UncheckedAccount<'info>,
    pub token_program: Program<'info, Token>,
    /// CHECK: This is the token account that we want to mint tokens to
    #[account(mut)]
    pub token_account: UncheckedAccount<'info>,
    /// CHECK: the authority of the mint account
    #[account(mut)]
    pub authority: Signer<'info>,
    /// CHECK: Metaplex will check this
    pub token_metadata_program: UncheckedAccount<'info>,
}

I've checked everything back and forth, but couldn't find an account that I didn't fill out. The function that calls the program looks like this:

await program.methods.mintToken(
      nftTitle, nftSymbol, nftUri
    ).accounts({
      metadata: metadataAddress,
      mint: mintKey.publicKey,
      tokenProgram: TOKEN_PROGRAM_ID,
      tokenAccount: associatedTokenAccount,
      authority: key,
      tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
    })
    .rpc();

Can someone please help with why the error occurs?

1 Answer 1

4

I think you may need to include Rent for the metadata account:

#[derive(Accounts)]
pub struct MintToken<'info> {
    ...
    pub rent: Sysvar<'info, Rent>,
}

Then just add:

ctx.accounts.rent.to_account_info(),
1
  • 2
    Also apparently I needed to add the System Program to it as well. That's something to look out for in the future. Thank you for the answer though! ^^
    – Kiwi
    Commented Jul 20, 2022 at 18:12

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.