首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要帮助构建从母版nft创建新版本nft的函数。

需要帮助构建从母版nft创建新版本nft的函数。
EN

Stack Overflow用户
提问于 2022-06-22 04:07:21
回答 1查看 210关注 0票数 0

图像链接到我的代码

https://i.stack.imgur.com/UWtpj.png

我目前正在用Rust/Anchor-Solana编写一个Solana元复合NFT程序,特别是编写一个逻辑来从主版NFT创建一个版本NFT。

在调用mpl_token_metadata::instruction::mint_new_edition_from_master_edition_via_token指令时,我发现它需要metadatametadata_mint字段作为参数。然而,在元文档中,指令似乎只需要主记录元数据帐户。

问题:

我应该在每个字段(metadatametadata_mint)中输入哪个帐户键或值,以及为什么?

代码:

代码语言:javascript
复制
pub fn create_new_edition_nft(
        ctx: Context<CreateNewEdition>,
        edition: 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.metadata.key(), edition
        ), edition_infos.as_slice())?;

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

#[derive(Accounts)]
pub struct CreateNewEdition<'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>,
    #[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>,    
    // #[account(mut)]
    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>,
}

文档参考:

从主版打印新版本的文档:

https://docs.metaplex.com/programs/token-metadata/instructions#print-a-new-edition-from-a-master-edition

EN

回答 1

Stack Overflow用户

发布于 2022-06-23 04:26:49

您正在讨论的元工文档是solana指令的文档,而不是锈蚀api的文档。它们是不同的。如果你看一下生锈代码,你就会看到不同之处。

文档中描述的帐户与代码提供的帐户相匹配:

代码语言:javascript
复制
let accounts = vec![
   AccountMeta::new(new_metadata, false),
   AccountMeta::new(new_edition, false),
   AccountMeta::new(master_edition, false),
   AccountMeta::new(new_mint, false),
   AccountMeta::new(edition_mark_pda, false),
   AccountMeta::new_readonly(new_mint_authority, true),
   AccountMeta::new(payer, true),
   AccountMeta::new_readonly(token_account_owner, true),
   AccountMeta::new_readonly(token_account, false),
   AccountMeta::new_readonly(new_metadata_update_authority, false),
   AccountMeta::new_readonly(metadata, false),
   AccountMeta::new_readonly(spl_token::id(), false),
   AccountMeta::new_readonly(solana_program::system_program::id(), false),
   AccountMeta::new_readonly(sysvar::rent::id(), false),
];

您正在讨论的变量metadata_mint用于计算链上edition_mark_pda地址的地址:

代码语言:javascript
复制
    let (edition_mark_pda, _) = Pubkey::find_program_address(
        &[
            PREFIX.as_bytes(),
            program_id.as_ref(),
            metadata_mint.as_ref(),
            EDITION.as_bytes(),
            as_string.as_bytes(),
        ],
        &program_id,
    );

当您将此与文档进行比较时,您将看到应该提供哪些内容:

版pda标记创建-将检查是否存在.(“元数据”、程序id、主元数据薄荷id、“edition_number”、edition_number不是您在args中传递的版本号,实际上是edition_number=层(edition_number/ edition _MARKER_BIT_SIZE))。

metadata :=主记录元数据帐户

metadata_mint :=主元数据薄荷id

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72709581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档