1

I've tried to follow and complete the following guide to create an NFT through Anchor, but after finishing writing the code following each step throroughly following error while compiling:

error[E0425]: cannot find value `mint` in this scope
   --> programs/solana-try-nft/src/lib.rs:144:36
    |
144 |     address=find_metadata_account(&mint.key()).0,
    |                                    ^^^^ not found in this scope
    |
help: consider importing this function
    |
1   + use anchor_spl::token::accessor::mint;
    |

error[E0425]: cannot find value `mint` in this scope
   --> programs/solana-try-nft/src/lib.rs:150:42
    |
150 |     address=find_master_edition_account(&mint.key()).0,
    |                                          ^^^^ not found in this scope
    |
help: consider importing this function
    |
1   + use anchor_spl::token::accessor::mint;
    |

For more information about this error, try `rustc --explain E0425`.
error: could not compile `solana-try-nft` (lib test) due to 2 previous errors
Error: Building IDL failed 

This is the struct I am trying to create:

#[derive(Accounts)]
pub struct InitNFT<'info> {
    /// CHECK: ok, we are passing this account ourselves
    #[account(mut, signer)]
    pub signer: AccountInfo<'info>,
    #[account(
        init,
        payer = signer,
        mint::decimals = 0,
        mint::authority = signer.key(),
        mint::freeze_authority = signer.key(),
    )]
    pub mint: Account<'info, Mint>,
    #[account(
        init_if_needed,
        payer = signer,
        associated_token::mint = mint,
        associated_token::authority = signer,
    )]
    pub associated_token_account: Account<'info, TokenAccount>,
    /// CHECK - address
    #[account(
        mut,
        address=find_metadata_account(&mint.key()).0,
    )]
    pub metadata_account: AccountInfo<'info>,
    /// CHECK: address
    #[account(
        mut,
        address=find_master_edition_account(&mint.key()).0,
    )]
    pub master_edition_account: AccountInfo<'info>,

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

Both lines that refer to the address like address=find_master_edition_account(&mint.key()).0, and address=find_metadata_account(&mint.key()).0, where a reference to mint is used are being flagged as mint not known in the scope. Despite having imported the needed dependencies. How could I fix this?

2
  • What dependency versions are you using for anchor, anchor_spl, and mpl_token_metadata?
    – Joey Meere
    Commented Jun 15 at 23:19
  • mpl-token-metadata = "4.1.2" is what I have, along with solana version 1.18.8, and solana-program 1.18.2
    – R. Vargas
    Commented Jun 16 at 17:42

2 Answers 2

1

This tutorial uses an outdated version of mpl_token_metadata.

Switch to a Metaplex version >0.4.0 e.g mpl-token-metadata = "4.1.2"

Update your Solana version to 1.18.8. You'll face some stack overflow errors and this has been solved by downgrading the solana-program crate to 1.18.2

cargo update -p solana-program@current-version --precise 1.18.2. You can find current-version by looking at your Cargo.lock file

You'll also need to update your lib.rs as there have been some changes between version 1 and 4 of Metaplex

You'll need to replace the find_metadata_account and find_master_edition_account with

use mpl_token_metadata::accounts::{ MasterEdition, Metadata as MetadataAccount };

/// CHECK: metadata address check
    #[account(
        mut,
        address = MetadataAccount::find_pda(&mint.key()).0,
    )]

/// CHECK: master edition address address check
    #[account(
        mut,
        address = MasterEdition::find_pda(&mint.key()).0,
    )]
    pub master_edition_account: AccountInfo<'info>,

2
  • Tried this but it didn't solve it. I got the same problem signaled on the same place (mint.key()).
    – R. Vargas
    Commented Jun 16 at 17:40
  • I've posted the solution on the Calyptus Discord. Feel free to ping me if anything else comes up
    – Jimii
    Commented Jun 16 at 18:52
0

After trying the solution further explained by Jimii I was able to make it build.

Here is what changed:

Anchor version used: 0.29.0 Rustup Version: 1.76.0 Rustup Nightly Version: nightly-2024-02-04 anchor-lang: version = "0.29.0", features = ["init-if-needed"] anchor-spl: version = "0.29.0", features = ["metadata"]

Dependency usage changed: From mpl types DataV2 to anchor_spl::metadata::mpl_token_metadata::types::DataV2

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.