6

I run my code, and it shows, looks like I need to intro pub token_program: Program<'info, Token>, but I did, you can get more information from my code below


error[E0599]: no associated item named `__anchor_private_insert_idl_defined` found for struct `anchor_spl::token::Mint` in the current scope
   --> programs/sol404/src/instructions/createmint.rs:153:10
    |
153 | #[derive(Accounts)]
    |          ^^^^^^^^ associated item not found in `Mint`
    |
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0599]: no associated item named `__anchor_private_insert_idl_defined` found for struct `anchor_spl::token::TokenAccount` in the current scope
   --> programs/sol404/src/instructions/createmint.rs:153:10
    |
153 | #[derive(Accounts)]
    |          ^^^^^^^^ associated item not found in `TokenAccount`
    |
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)


here is my code, I try to create a mint and a ATA account, and I used

#[derive(Accounts)]
pub struct CreateMint<'info> {
    // Use ADMIN_PUBKEY as constraint, only the specified admin can invoke this instruction
    #[account(
        mut,
        address = ADMIN_PUBKEY
    )]
    pub admin: Signer<'info>,

    // The PDA is both the address of the mint account and the mint authority
    #[account(
        init,
        seeds = [b"jelly"],
        bump,
        payer = admin,
        mint::decimals = 9,
        mint::authority = jelly_token_mint,
    )]
    pub jelly_token_mint: Account<'info, Mint>,
    
    ///CHECK: Using "address" constraint to validate metadata account address, this account is created via CPI in the instruction
    #[account(
        mut,
        address = MetadataAccount::find_pda(&jelly_token_mint.key()).0,
    )]
    pub jelly_metadata_account: UncheckedAccount<'info>,


    #[account(
        init,
        payer = admin,
        associated_token::mint = jelly_token_mint,
        associated_token::authority = admin,
    )]
    pub jelly_token_account: Account<'info, TokenAccount>,


    pub associated_token_program: Program<'info, AssociatedToken>,
    pub token_program: Program<'info, Token>,
    pub token_metadata_program: Program<'info, Metadata>,
    pub system_program: Program<'info, System>,
    pub rent: Sysvar<'info, Rent>,
}

and here is my cargo.toml, I am not sure whether it is a version problem

[package]
name = "sol404"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "sol404"

[features]
default = []
cpi = ["no-entrypoint"]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = {version = "0.29.0", features = ["init-if-needed"]}
anchor-spl = {version = "0.29.0", features = ["metadata"]}
mpl-token-metadata = "4.1.2"
solana-program = "1.18.11"

I can't get any useful information from google, and GPT, anyone can help me?

1 Answer 1

11

This is because all types that are being used in the accounts struct require IdlBuild trait implementation to generate an IDL.

To fix the errors you have, you can enable anchor-spl/idl-build feature by including it in the idl-build feature:

idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]

As a side note, consider checking out release notes for Anchor 0.29.0 and 0.30.0 because both of them mention this (and a lot more).

2
  • I found that's just because I initialize the folder with anchor0.30.0
    – papi
    Commented Apr 22 at 10:19
  • Same problem from: no function or associated item named create_type found for struct anchor_spl::token::TokenAccount in the current scope
    – Russo
    Commented Jul 15 at 15:20

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.