1

I have been struggling with minting new edition form master edition. Its been days now, and I can not solve the problem.

onchain code

        ctx.accounts.new_metadata.to_account_info(),
        ctx.accounts.new_edition.to_account_info(),
        ctx.accounts.master_edition.to_account_info(),
        ctx.accounts.new_mint.to_account_info(),
        ctx.accounts.edition_mark_pda.to_account_info(),
        ctx.accounts.new_mint_authority.to_account_info(),
        ctx.accounts.payer.to_account_info(),
        ctx.accounts.token_account_owner.to_account_info(),
        ctx.accounts.token_account.to_account_info(),
        ctx.accounts.new_metadata_update_authority.to_account_info(),
        ctx.accounts.metadata.to_account_info(),
        ctx.accounts.token_program.to_account_info(),
        ctx.accounts.system_program.to_account_info(),
        ctx.accounts.rent.to_account_info(),
    ];
    invoke(
        &mint_new_edition_from_master_edition_via_token(
            TOKEN_METADATA_ID,
            ctx.accounts.new_metadata.key(),
            ctx.accounts.new_edition.key(),
            ctx.accounts.master_edition.key(),
            ctx.accounts.new_mint.key(),
            ctx.accounts.new_mint_authority.key(),
            ctx.accounts.payer.key(),
            ctx.accounts.token_account_owner.key(),
            ctx.accounts.token_account.key(),
            ctx.accounts.new_metadata_update_authority.key(),
            ctx.accounts.metadata.key(),
            ctx.accounts.mint.key(),
            1,
        ),
        &accounts.as_slice(),
    )?;

    Ok(())
}

#[derive(Accounts)]
pub struct MintEditionsFromMaster<'info>{
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub new_metadata: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub new_edition: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub master_edition: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(
        mut
    )]
    pub new_mint: AccountInfo<'info>,
///CHECK: this is not dangerous
    #[account(mut)]
    pub mint: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub edition_mark_pda: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub new_mint_authority: Signer<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub payer: Signer<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub token_account_owner: Signer<'info>,
    ///CHECK: this is not dangerous
    #[account(
        mut
    )]
    pub token_account: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub new_metadata_update_authority: AccountInfo<'info>,
    ///CHECK: this is not dangerous
    #[account(mut)]
    pub metadata: AccountInfo<'info>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub rent: Sysvar<'info, Rent>,
}

and this is how I'm deriving the PDAs from client

//Old mint key that is the master mint
const mintKey: anchor.web3.Keypair = anchor.web3.Keypair.generate();
//new mint key that will be edition of the master edition
const newMint: anchor.web3.Keypair = anchor.web3.Keypair.generate();

const [newMetaData, bump ]= (await anchor.web3.PublicKey.findProgramAddress(
      [Buffer.from('metadata'), TOKEN_METADATA_PROGRAM_ID.toBuffer(), newMint.publicKey.toBuffer()],
      TOKEN_METADATA_PROGRAM_ID
    ));
const newEditionAddress = (await anchor.web3.PublicKey.findProgramAddress(
      [
        Buffer.from("metadata"),
        TOKEN_METADATA_PROGRAM_ID.toBuffer(),
        newMint.publicKey.toBuffer(),
        Buffer.from("edition"),
      ],
      TOKEN_METADATA_PROGRAM_ID
    ))[0];

const masterEditionAddress = (await anchor.web3.PublicKey.findProgramAddress(
      [
        Buffer.from("metadata"),
        TOKEN_METADATA_PROGRAM_ID.toBuffer(),
        mintKey.publicKey.toBuffer(),
        Buffer.from("edition"),
      ],
      TOKEN_METADATA_PROGRAM_ID
    ))[0];
   const eidtionNumber = new anchor.BN( (Math.floor(1/248)));
     console.log("Edition Number", eidtionNumber);
    const [editionMarker] = (await anchor.web3.PublicKey.findProgramAddress(
      [
        Buffer.from("metadata"),
        TOKEN_METADATA_PROGRAM_ID.toBuffer(),
        mintKey.publicKey.toBuffer(),
        Buffer.from("edition"),
        Buffer.from(eidtionNumber.toString())
      ],
      TOKEN_METADATA_PROGRAM_ID
    ));
const newTokenAccount = await getAssociatedTokenAddress(
      newMint.publicKey,
      buyerWallet.publicKey
    );
const getMetadata = async (mint: anchor.web3.PublicKey): Promise<anchor.web3.PublicKey> => {
      return (await anchor.web3.PublicKey.findProgramAddress(
        [
          Buffer.from("metadata"),
          TOKEN_METADATA_PROGRAM_ID.toBuffer(),
          mint.toBuffer(),
        ],
        TOKEN_METADATA_PROGRAM_ID
      ))[0];
    };
    const metadataAddress = await getMetadata(mintKey.publicKey);

const tx = await program.methods.mintNewEdition().accounts({
      mint:mintKey.publicKey,
      newMetadata: newMetaData,
      newEdition:newEditionAddress,
      masterEdition: masterEditionAddress,
      newMint: newMint.publicKey,
      editionMarkPda:editionMarker,
      newMintAuthority: buyerWallet.publicKey,
      payer: buyerWallet.publicKey,
      tokenAccountOwner: buyerWallet.publicKey ,
      tokenAccount: newTokenAccount,
      newMetadataUpdateAuthority:buyerWallet.publicKey,
      metadata:metadataAddress,
      // tokenMetadataProgram:TOKEN_METADATA_PROGRAM_ID,
      associatedTokenProgram:ASSOCIATED_PROGRAM_ID,
      systemProgram:systemProgramId,
      tokenProgram: tokenProgramId,
      rent: anchor.web3.SYSVAR_RENT_PUBKEY,
    }).signers([buyerWallet]).rpc();

I have done a lot of R&D the but no success. Metaplex docs doesn't help as well.

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing

Above is the error I'm getting when executing code. PS: Master account is creating successfully, have checked that on solana explorer '2HtSdJ8Xo4PZs7oPhqYDjo2gtinhGY2CW4vgqpa4KRDb' you can check as well this is the NFT mint.

1 Answer 1

0

The mint_new_edition_from_master_edition_via_token instruction needs the mint of the master edition in its second to last argument. However here you're passing in mint which is a newly generated account and thus is wrong.

mint should be masterEditionMint you used in creating your master edition.

Edit:
Add ctx.accounts.token_metadata_program.to_account_info() to the accounts in your on-chain code, and make the required change to the client-side.

Also, tokenAccount should be the same account that the masterEdition nft was minted into, not a newly created token account.

6
  • Thanks for help @ademola, you are right because I did't post all the code here, but that mint is actually the masterEditionMint which comes when I'm minting the NFT and creating masterEdition, I have just kept it there to make sense that I'm passing the mint as well. But unfortunately it's not working. can you see it more thoroughly I'll provide any thing you need I'm really stuck here. I hv seen you answering this question on other similar posts as well but unfortunately they are mystery yet.
    – Naveed Ali
    Commented Nov 29, 2022 at 5:38
  • I'll look at it and edit my answer. This particular problem is tricky because there's a lot of accounts that could be the issue
    – Ademola
    Commented Nov 29, 2022 at 6:10
  • There are two accounts I'm suspicious about 1: Token Account Owner its description says owner of token account containing master token I don't really get it, for that I'm passing a NFT buyer account in this, am I correct? 2: Token Account its description says token account containing token from master metadata mint I can't absorb it as well, I mean usually we pass the mint + wallet to derive the token account, so I have passed token account derived from new_mint + buyer_wallet is that correct? and the whole scenario is that, eg: I want 10 same nft to be sold to different buyers
    – Naveed Ali
    Commented Nov 29, 2022 at 7:11
  • I updated the answer. If that doesn't fix it then check out this repo for comparison.
    – Ademola
    Commented Nov 29, 2022 at 7:14
  • Thanks ademola, the repo really worked for me, any one facing the same issue can follow that.
    – Naveed Ali
    Commented Dec 2, 2022 at 11:05

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.