1

I'm getting an error while creating a new token mint. I'm passing all the accounts but still get "Error: NotEnoughAccountKeys".

Here's my Anchor Program:

pub fn create_mint(
        ctx: Context<CreateMint>,
        uri: String,
        name: String,
        symbol: String,
    ) -> Result<()> {

        // PDA seeds and bump to "sign" for CPI
        let seeds = b"solxmint_token";
        let bump = *ctx.bumps.get("token_mint").unwrap();
        let signer: &[&[&[u8]]] = &[&[seeds, &[bump]]];

        // On-chain token metadata for the mint
        let data_v2 = DataV2 {
            name,
            symbol,
            uri,
            seller_fee_basis_points: 0,
            creators: None,
            collection: None,
            uses: None,
        };

        // CPI Context
        let cpi_ctx = CpiContext::new_with_signer(
            ctx.accounts.token_metadata_program.to_account_info(),
            CreateMetadataAccountsV3 {
                metadata: ctx.accounts.token_metadata_account.to_account_info(),  // Metadata
                mint: ctx.accounts.token_mint.to_account_info(),                  // Mint
                mint_authority: ctx.accounts.token_mint.to_account_info(),        // Mint authority
                payer: ctx.accounts.owner.to_account_info(),                      // Payer
                update_authority: ctx.accounts.owner.to_account_info(),           // Update authority
                system_program: ctx.accounts.system_program.to_account_info(),    // System program
                rent: ctx.accounts.rent.to_account_info(),                        // Rent
            },
            signer,
        );

        create_metadata_accounts_v3(
            cpi_ctx, // cpi context
            data_v2, // token metadata
            true,    // is_mutable
            true,    // update_authority_is_signer
            None,    // collection details
        )?;

        Ok(())
    }
#[derive(Accounts)]
pub struct CreateMint<'info> {
    #[account(
        init,
        seeds = [b"solxmint_token"],
        bump,
        payer = owner,
        mint::decimals = 9,
        mint::authority = token_mint,
    )]
    pub token_mint: Account<'info, Mint>,

    /// CHECK:
    #[account(mut)]
    pub token_metadata_account: AccountInfo<'info>,
    #[account(mut)]
    pub owner: Signer<'info>,
    pub token_program: Program<'info, Token>,
    pub token_metadata_program: Program<'info, Metadata>,
    pub rent: Sysvar<'info, Rent>,
    pub system_program: Program<'info, System>,
}

Here's my test case:

it("Can Create a Mint", async () => {
    try {
      const tokenMintPDA = PublicKey.findProgramAddressSync([Buffer.from("solxmint_token")], program.programId)[0];
      const tokenMintMetadataPDA = metaplex.nfts().pdas().metadata({ mint: tokenMintPDA });
      // const tokenMintMetadataPDA = PublicKey.findProgramAddressSync([Buffer.from("metadata"), METADATA_PROGRAM_ID.toBuffer(), tokenMintPDA.toBuffer()], METADATA_PROGRAM_ID)[0];

      const tx = await program.methods.createMint("TestURI", "TestName", "TST").accounts({
        tokenMint: tokenMintPDA,
        tokenMetadataAccount: tokenMintMetadataPDA,
        tokenMetadataProgram: METADATA_PROGRAM_ID,
        tokenProgram: TOKEN_PROGRAM_ID,
        owner: KEYPAIR.publicKey,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
        systemProgram: anchor.web3.SystemProgram.programId,
      }).signers([KEYPAIR]).rpc();

      console.log("Your transaction signature", tx);
    } catch (e: any) {
      console.log(e);
    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.