I'm trying to mint an NFT using Anchor but the current docs are out of date. Does anyone have a simple example?

2 Answers 2


Hey there with anchor you can add mpl-token-metadata to your cargo.

mpl-token-metadata = { version = "*"}

make sure you import:

use mpl_token_metadata::{
    state::{Creator, Collection},
    instruction::{create_metadata_accounts_v3, create_master_edition_v3}

So a very basic example would be:

initializer: Signer<'info>,
    payer = initializer,
    mint::authority = auth,
    mint::freeze_authority = auth,
    mint::decimals = 0
nft: InterfaceAccount<'info, Mint>
    payer = initializer,
    associated_token::mint = nft,
    associated_token::authority = initializer,
nft_ata: InterfaceAccount<'info, TokenAccount>,
///CHECK: account is initialized in the ix
metadata: UncheckedAccount<'info>,
///CHECK: account is initialized in the ix
master_edition: UncheckedAccount<'info>,
    seeds=[b"auth", config.key().as_ref()],
    bump = config.auth_bump
///CHECK: This is safe. It's just used to sign things
auth: UncheckedAccount<'info>,
mpl_program: Program<'info, Metadata>,

impl<'info> ...<'info> {
    pub fn issue_nft(
) -> Result<()> {
    let accounts = MintTo {
        mint: self.nft.to_account_info(),
        to: self.nft_ata.to_account_info(),
        authority: self.auth.to_account_info()

    let seeds = &[

    let signer_seeds = &[&seeds[..]];

    let ctx = CpiContext::new_with_signer(

// Mint NFT
    mint_to(ctx, 1)

// Create Metadata
    let create_metadata_ix = create_metadata_accounts_v3(
//In case you have a collection and you added a collection acc
Some(Collection { verified: false, key: self.collection.key() }),

 // Create Master Edition
    let create_master_edition_ix = create_master_edition_v3(

If you want to do a collection, you would need to add a collection account To the account struct. Mint this collection nft, create the metadata and master edition( its existence is proof of the Non-Fungibility of the token). Then after minting the nfts you need to pass the collection account, set the collection when creating the metadata.


I've created a simple localhost example repo.

Specific setups have been broken down into separate commits.

Note: It uses older mpl-token-metadata (v1.13.1) and has the NFT metadata JSON stored on GitHub as centralized storage for modification.

Open to PRs to get this to use latest version!

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.