简体   繁体   中英

Anchor test transaction failed with "An account required by the instruction is missing"

I am trying to code an anchor code where I can mint a new edition nft from a master edition ntf. I looked into the metaplex documentation and rust api documentation to come up with the code below, and am not sure why I am getting this "Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing" message.

For your reference, here I provide both my program script in lib.rs and test script in ts file

lib.rs

use anchor_lang::prelude::*;
use anchor_lang::solana_program::program::invoke;
use anchor_spl::token;
use anchor_spl::token::{MintTo, Token};
use mpl_token_metadata::instruction::{create_master_edition_v3, create_metadata_accounts_v2,mint_new_edition_from_master_edition_via_token,};

declare_id!("4kYKrkgyuRppwg6bxxKkirQ5wtddZQpkLA2Xp9Fo2YNn");

#[program]
pub mod solana_blockchain {
    use super::*;

    pub fn mint_nft(ctx: Context<MintNFT>) -> Result<()> {
        msg!("Initializing Mint NFT");
        let cpi_accounts = MintTo {
            mint: ctx.accounts.mint.to_account_info(),
            to: ctx.accounts.token_account.to_account_info(),
            authority: ctx.accounts.payer.to_account_info(),
        };
        msg!("CPI Accounts Assigned");
        let cpi_program = ctx.accounts.token_program.to_account_info();
        msg!("CPI Program Assigned");
        let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
        msg!("CPI Context Assigned");
        token::mint_to(cpi_ctx, 1)?;
        msg!("Token Minted !!!");
        Ok(())
    }

    pub fn create_metadata_account(
        ctx: Context<CreateMetadataAccount>,
        creator_key: Pubkey,
        uri: String,
        title: String,
        symbol: String,
    ) -> Result<()> {
        msg!("Initializing the creation of a new metadata account");
        let account_info = vec![
            ctx.accounts.metadata.to_account_info(),
            ctx.accounts.mint.to_account_info(),
            ctx.accounts.mint_authority.to_account_info(),
            ctx.accounts.payer.to_account_info(),
            ctx.accounts.token_metadata_program.to_account_info(),
            ctx.accounts.token_program.to_account_info(),
            ctx.accounts.system_program.to_account_info(),
            ctx.accounts.rent.to_account_info(),
        ];
        msg!("Account Info Assigned");
        let creator = vec![
            mpl_token_metadata::state::Creator {
                address: creator_key,
                verified: false,
                share: 100,
            },
            mpl_token_metadata::state::Creator {
                address: ctx.accounts.mint_authority.key(),
                verified: false,
                share: 0,
            },
        ];
        msg!("Creator Assigned");
        // let symbol = std::string::ToString::to_string("LWB");
        invoke(
            &create_metadata_accounts_v2(
                ctx.accounts.token_metadata_program.key(),
                ctx.accounts.metadata.key(),
                ctx.accounts.mint.key(),
                ctx.accounts.mint_authority.key(),
                ctx.accounts.payer.key(),
                ctx.accounts.payer.key(),
                title,
                symbol,
                uri,
                Some(creator),
                1,
                true,
                false,
                None,
                None,
            ),
            account_info.as_slice(),
        )?;
        msg!("Metadata Account Created !!!");
        // let master_edition_infos = vec![
        //     ctx.accounts.master_edition.to_account_info(),
        //     ctx.accounts.mint.to_account_info(),
        //     ctx.accounts.mint_authority.to_account_info(),
        //     ctx.accounts.payer.to_account_info(),
        //     ctx.accounts.metadata.to_account_info(),
        //     ctx.accounts.token_metadata_program.to_account_info(),
        //     ctx.accounts.token_program.to_account_info(),
        //     ctx.accounts.system_program.to_account_info(),
        //     ctx.accounts.rent.to_account_info(),
        // ];
        // msg!("Master Edition Account Infos Assigned");
        // invoke(
        //     &create_master_edition_v3(
        //         ctx.accounts.token_metadata_program.key(),
        //         ctx.accounts.master_edition.key(),
        //         ctx.accounts.mint.key(),
        //         ctx.accounts.payer.key(),
        //         ctx.accounts.mint_authority.key(),
        //         ctx.accounts.metadata.key(),
        //         ctx.accounts.payer.key(),
        //         None,
        //     ),
        //     master_edition_infos.as_slice(),
        // )?;
        // msg!("Master Edition Nft Minted !!!");
        Ok(())
    }

    pub fn create_master_edition(
        ctx: Context<CreateMasterEdition>,
        max_supply: Option<u64>
    ) -> Result<()> {
        let master_edition_infos = vec![
            ctx.accounts.master_edition.to_account_info(),
            ctx.accounts.mint.to_account_info(),
            ctx.accounts.mint_authority.to_account_info(),
            ctx.accounts.payer.to_account_info(),
            ctx.accounts.metadata.to_account_info(),
            ctx.accounts.token_metadata_program.to_account_info(),
            ctx.accounts.token_program.to_account_info(),
            ctx.accounts.system_program.to_account_info(),
            ctx.accounts.rent.to_account_info(),
        ];
        msg!("Master Edition Account Infos Assigned");
        invoke(
            &create_master_edition_v3(
                ctx.accounts.token_metadata_program.key(),
                ctx.accounts.master_edition.key(),
                ctx.accounts.mint.key(),
                ctx.accounts.payer.key(),
                ctx.accounts.mint_authority.key(),
                ctx.accounts.metadata.key(),
                ctx.accounts.payer.key(),
                max_supply,
            ),
            master_edition_infos.as_slice(),
        )?;
        msg!("Master Edition Nft Minted !!!");
        Ok(())
    }

    pub fn create_new_edition_nft(
        ctx: Context<CreateNewEdition>,
        en: u64,
    ) -> Result<()> {
        let edition_infos = vec![
            ctx.accounts.token_program.to_account_info(),
            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.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.system_program.to_account_info(),
            ctx.accounts.rent.to_account_info(),
        ];
        msg!("Edition Account Infos Assigned");
        invoke(&mint_new_edition_from_master_edition_via_token(
            ctx.accounts.token_program.key(),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.original_mint.key(), en
        ), edition_infos.as_slice())?;

        msg!("A New Edition Nft Minted !!!");
        Ok(())
    }
}

#[derive(Accounts)]
pub struct MintNFT<'info> {
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub mint: UncheckedAccount<'info>,
    // #[account(mut)]
    pub token_program: Program<'info, Token>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub token_account: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub payer: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct CreateMetadataAccount<'info> {
    #[account(mut)]
    pub mint_authority: Signer<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub mint: UncheckedAccount<'info>,
    // #[account(mut)]
    pub token_program: Program<'info, Token>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub metadata: UncheckedAccount<'info>,
    // /// CHECK: This is not dangerous because we don't read or write from this account
    // #[account(mut)]
    // pub token_account: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub token_metadata_program: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub payer: AccountInfo<'info>,
    pub system_program: Program<'info, System>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub rent: AccountInfo<'info>,
    // /// CHECK: This is not dangerous because we don't read or write from this account
    // #[account(mut)]
    // pub master_edition: UncheckedAccount<'info>,
}

#[derive(Accounts)]
pub struct CreateMasterEdition<'info> {
    #[account(mut)]
    pub mint_authority: Signer<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub mint: UncheckedAccount<'info>,
    // #[account(mut)]
    pub token_program: Program<'info, Token>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub metadata: UncheckedAccount<'info>,
    // /// CHECK: This is not dangerous because we don't read or write from this account
    // #[account(mut)]
    // pub token_account: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub token_metadata_program: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub payer: AccountInfo<'info>,
    pub system_program: Program<'info, System>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub rent: AccountInfo<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub master_edition: UncheckedAccount<'info>,
}

#[derive(Accounts)]
pub struct CreateNewEdition<'info> {
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub original_mint: UncheckedAccount<'info>,    
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub new_metadata: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub new_edition: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub master_edition: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub new_mint: UncheckedAccount<'info>,    
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub edition_mark_pda: UncheckedAccount<'info>,    
    #[account(mut)]
    pub new_mint_authority: Signer<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub payer: AccountInfo<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub token_account_owner: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub token_account: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub new_metadata_update_authority: UncheckedAccount<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub metadata: UncheckedAccount<'info>,    
    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub rent: AccountInfo<'info>,
}

test file script

import * as anchor from "@project-serum/anchor";
import { Program, Wallet } from "@project-serum/anchor";
const assert = require("assert");
import {
  createAssociatedTokenAccountInstruction,
  createInitializeMintInstruction,
  getAssociatedTokenAddress,
  MINT_SIZE,
  TOKEN_PROGRAM_ID,
} from "@solana/spl-token"; // IGNORE THESE ERRORS IF ANY
import { SolanaBlockchain } from "../target/types/solana_blockchain";
const { SystemProgram, PublicKey } = anchor.web3;

describe("metaplex-anchor-nft", () => {
  // Configure the client to use the local cluster.
  const provider = anchor.AnchorProvider.env();
  const wallet = provider.wallet as Wallet;
  anchor.setProvider(provider);
  const program = anchor.workspace
    .SolanaBlockchain as Program<SolanaBlockchain>;

  //TODO: Check whether if the creator key has to match with the mint key

  const mintKey: anchor.web3.Keypair = anchor.web3.Keypair.generate();

  it("creates a new mint account!", async () => {
    //create a new keypair for a new mint account

    const lamports: number =
      await program.provider.connection.getMinimumBalanceForRentExemption(
        MINT_SIZE
      );

    console.log(`mintKey address is ${mintKey.publicKey}`);
    const NftTokenAccount = await getAssociatedTokenAddress(
      mintKey.publicKey,
      wallet.publicKey
    );
    console.log("NFT Account: ", NftTokenAccount.toBase58());

    const mint_tx = new anchor.web3.Transaction().add(
      anchor.web3.SystemProgram.createAccount({
        fromPubkey: wallet.publicKey,
        newAccountPubkey: mintKey.publicKey,
        space: MINT_SIZE,
        programId: TOKEN_PROGRAM_ID,
        lamports,
      }),
      createInitializeMintInstruction(
        mintKey.publicKey,
        0,
        wallet.publicKey,
        wallet.publicKey
      ),
      createAssociatedTokenAccountInstruction(
        wallet.publicKey,
        NftTokenAccount,
        wallet.publicKey,
        mintKey.publicKey
      )
    );

    const res = await program.provider.sendAndConfirm(mint_tx, [mintKey]);
    console.log(
      await program.provider.connection.getParsedAccountInfo(mintKey.publicKey)
    );

    console.log("Account: ", res);
    console.log("Mint key: ", mintKey.publicKey.toString());
    console.log("User: ", wallet.publicKey.toString());

    const current_supply_before = parseInt(
      (await provider.connection.getTokenSupply(mintKey.publicKey)).value.amount
    );

    console.log(`current supply is ${current_supply_before}`);

    assert.ok(current_supply_before === 0);

    const tx = await program.methods
      .mintNft()
      .accounts({
        mint: mintKey.publicKey,
        tokenAccount: NftTokenAccount,
        tokenProgram: TOKEN_PROGRAM_ID,
        payer: wallet.publicKey,
      })
      .rpc();

    console.log("Your transaction signature", tx);
    const current_supply_after = parseInt(
      (await provider.connection.getTokenSupply(mintKey.publicKey)).value.amount
    );
    console.log(`current supply is ${current_supply_after}`);

    assert.ok(current_supply_after === 1);
  });

  it("Is creates a new metadata account!", async () => {
    // Add your test here.

    const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey(
      "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
    );
    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);

    console.log("Metadata address: ", metadataAddress.toBase58());

    const tx = await program.methods
      .createMetadataAccount(
        mintKey.publicKey,
        "https://gateway.pinata.cloud/ipfs/QmQNtiFGzdo8eQbmHTGpxX3LwhmWe49StstvLqXx8GRt3E",
        "Ronnie Coleman NFT",
        "LWB"
      )
      .accounts({
        mintAuthority: wallet.publicKey,
        mint: mintKey.publicKey,
        tokenProgram: TOKEN_PROGRAM_ID,
        metadata: metadataAddress,
        tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
        payer: wallet.publicKey,
        systemProgram: SystemProgram.programId,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
      })
      .rpc();
    console.log("Your transaction signature", tx);
  });

  it("Is creates a new master account!", async () => {
    // Add your test here.

    const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey(
      "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
    );
    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 getMasterEdition = 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(),
            Buffer.from("edition"),
          ],
          TOKEN_METADATA_PROGRAM_ID
        )
      )[0];
    };

    const metadataAddress = await getMetadata(mintKey.publicKey);
    const masterEdition = await getMasterEdition(mintKey.publicKey);

    // console.log("Metadata address: ", metadataAddress.toBase58());
    console.log("MasterEdition: ", masterEdition.toBase58());

    const tx = await program.methods
      .createMasterEdition(null)
      .accounts({
        mintAuthority: wallet.publicKey,
        mint: mintKey.publicKey,
        tokenProgram: TOKEN_PROGRAM_ID,
        metadata: metadataAddress,
        tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
        payer: wallet.publicKey,
        systemProgram: SystemProgram.programId,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
        masterEdition: masterEdition,
      })
      .rpc();
    console.log("Your transaction signature", tx);
  });
  it("creates a new mint edition nft from the original master edition nft", async () => {
    //generate a new mint account and a new associated token account
    const new_mintKey = anchor.web3.Keypair.generate();

    const lamports: number =
      await program.provider.connection.getMinimumBalanceForRentExemption(
        MINT_SIZE
      );

    console.log(`a new mintKey address is ${new_mintKey.publicKey}`);
    const NewNftTokenAccount = await getAssociatedTokenAddress(
      new_mintKey.publicKey,
      wallet.publicKey
    );
    console.log("The New NFT Account: ", NewNftTokenAccount.toBase58());

    const mint_tx = new anchor.web3.Transaction().add(
      anchor.web3.SystemProgram.createAccount({
        fromPubkey: wallet.publicKey,
        newAccountPubkey: new_mintKey.publicKey,
        space: MINT_SIZE,
        programId: TOKEN_PROGRAM_ID,
        lamports,
      }),
      createInitializeMintInstruction(
        new_mintKey.publicKey,
        0,
        wallet.publicKey,
        wallet.publicKey
      ),
      createAssociatedTokenAccountInstruction(
        wallet.publicKey,
        NewNftTokenAccount,
        wallet.publicKey,
        new_mintKey.publicKey
      )
    );

    const res = await program.provider.sendAndConfirm(mint_tx, [new_mintKey]);
    console.log(
      await program.provider.connection.getParsedAccountInfo(
        new_mintKey.publicKey
      )
    );

    console.log("Account: ", res);
    console.log("New Mint key: ", new_mintKey.publicKey.toString());
    console.log("User: ", wallet.publicKey.toString());

    const current_supply_before = parseInt(
      (await provider.connection.getTokenSupply(new_mintKey.publicKey)).value
        .amount
    );

    console.log(`current supply is ${current_supply_before}`);

    assert.ok(current_supply_before === 0);

    const tx = await program.methods
      .mintNft()
      .accounts({
        mint: new_mintKey.publicKey,
        tokenAccount: NewNftTokenAccount,
        tokenProgram: TOKEN_PROGRAM_ID,
        payer: wallet.publicKey,
      })
      .rpc();

    console.log("Your transaction signature", tx);
    const current_supply_after = parseInt(
      (await provider.connection.getTokenSupply(new_mintKey.publicKey)).value
        .amount
    );
    console.log(`current supply is ${current_supply_after}`);

    assert.ok(current_supply_after === 1);

    console.log(
      `a new mint account has been created at ${new_mintKey.publicKey}`
    );

    //TODO: get the metadata and master edition, as well as the token account of the original mint account
    const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey(
      "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
    );

    const NftTokenAccount = await getAssociatedTokenAddress(
      mintKey.publicKey,
      wallet.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);

    console.log("Metadata address: ", metadataAddress.toBase58());

    // const tx1 = await program.methods
    //   .createMetadataAccount(
    //     new_mintKey.publicKey,
    //     "https://gateway.pinata.cloud/ipfs/QmQNtiFGzdo8eQbmHTGpxX3LwhmWe49StstvLqXx8GRt3E",
    //     "Ronnie Coleman NFT",
    //     "LWB"
    //   )
    //   .accounts({
    //     mintAuthority: wallet.publicKey,
    //     mint: mintKey.publicKey,
    //     tokenProgram: TOKEN_PROGRAM_ID,
    //     metadata: metadataAddress,
    //     tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
    //     payer: wallet.publicKey,
    //     systemProgram: SystemProgram.programId,
    //     rent: anchor.web3.SYSVAR_RENT_PUBKEY,
    //   })
    //   .rpc();
    // console.log("Your transaction signature", tx1);

    const getMasterEdition = 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(),
            Buffer.from("edition"),
          ],
          TOKEN_METADATA_PROGRAM_ID
        )
      )[0];
    };

    const masterEdition = await getMasterEdition(mintKey.publicKey);

    console.log("MasterEdition: ", masterEdition.toBase58());

    // const tx2 = await program.methods
    //   .createMasterEdition(null)
    //   .accounts({
    //     mintAuthority: wallet.publicKey,
    //     mint: mintKey.publicKey,
    //     tokenProgram: TOKEN_PROGRAM_ID,
    //     metadata: metadataAddress,
    //     tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
    //     payer: wallet.publicKey,
    //     systemProgram: SystemProgram.programId,
    //     rent: anchor.web3.SYSVAR_RENT_PUBKEY,
    //     masterEdition: masterEdition,
    //   })
    //   .rpc();
    // console.log("Your transaction signature", tx2);

    //TODO: Create a new metadata account
    const newMetadataAddress = await getMetadata(new_mintKey.publicKey);

    console.log("New metadata address: ", newMetadataAddress.toBase58());

    const tx3 = await program.methods
      .createMetadataAccount(
        new_mintKey.publicKey,
        "https://gateway.pinata.cloud/ipfs/QmQNtiFGzdo8eQbmHTGpxX3LwhmWe49StstvLqXx8GRt3E",
        "Ronnie Coleman NFT",
        "LWB"
      )
      .accounts({
        mintAuthority: wallet.publicKey,
        mint: new_mintKey.publicKey,
        tokenProgram: TOKEN_PROGRAM_ID,
        metadata: newMetadataAddress,
        tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
        payer: wallet.publicKey,
        systemProgram: SystemProgram.programId,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
      })
      .rpc();
    console.log("Your transaction signature", tx3);
    //TODO: Create a new edition account

    const newMasterEdition = await getMasterEdition(new_mintKey.publicKey);

    console.log("New masterEdition: ", newMasterEdition.toBase58());

    const tx4 = await program.methods
      .createMasterEdition(null)
      .accounts({
        mintAuthority: wallet.publicKey,
        mint: new_mintKey.publicKey,
        tokenProgram: TOKEN_PROGRAM_ID,
        metadata: newMetadataAddress,
        tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
        payer: wallet.publicKey,
        systemProgram: SystemProgram.programId,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
        masterEdition: newMasterEdition,
      })
      .rpc();
    console.log("Your transaction signature", tx4);

    //TODO: CREATE a Edition Mark PDA

    const getEditionMarkPDA = async (
      mint: anchor.web3.PublicKey,
      edition_number: number
    ): Promise<anchor.web3.PublicKey> => {
      return (
        await anchor.web3.PublicKey.findProgramAddress(
          [
            Buffer.from("metadata"),
            TOKEN_METADATA_PROGRAM_ID.toBuffer(),
            mint.toBuffer(),
            Buffer.from("edition"),
            new Uint8Array(edition_number / 248),
          ],
          TOKEN_METADATA_PROGRAM_ID
        )
      )[0];
    };

    const editionMarkPDA = await getEditionMarkPDA(mintKey.publicKey, 1);

    console.log(`EditionMarkPDA address is ${editionMarkPDA}`);

    const tx5 = await program.methods
      .createNewEditionNft((1)[0])
      .accounts({
        originalMint: mintKey.publicKey,
        newMetadata: newMetadataAddress,
        newEdition: newMasterEdition,
        masterEdition: masterEdition,
        newMint: new_mintKey.publicKey,
        editionMarkPda: editionMarkPDA,
        newMintAuthority: wallet.publicKey,
        payer: wallet.publicKey,
        tokenAccountOwner: wallet.publicKey,
        tokenAccount: NftTokenAccount,
        newMetadataUpdateAuthority: wallet.publicKey,
        metadata: metadataAddress,
        tokenProgram: TOKEN_PROGRAM_ID,
        systemProgram: SystemProgram.programId,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
      })
      .rpc();

    console.log("Your transaction signature", tx5);
  });
});

Please let me know if you can tell me what am I missing or doing wrong here :(

Thanks!

I have not run your code but it seems like the accounts you are passing are incorrect.

  1. create_metadata_account :

    • The list of accounts can be found here
    • You are passing token_program while it's not needed.
    • update_authority_info is missing
  2. create_master_edition :

    • The list of accounts can be found here
    • update_authority_info is missing
  3. create_new_edition_nft :

    • The list of accounts can be found here
    • update_authority_info is missing
    • token_program_account_info is missing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM