2

Just need to know how to update NFT metadata after minting NFT. I am trying to use mpl_token_metadata::instruction::update_metadata_accounts_v2 for this. Don't know the correct way to use it or if there is some other way to update metadata.

    pub fn update_nft_metadata(ctx: Context<MintNFT>) -> Result<()> {
        let program_id = ctx.accounts.token_metadata_program.key();
        let metadata_account = ctx.accounts.metadata.key();
        let update_authority = ctx.accounts.mint_authority.key();
        let new_update_authority: Option<Pubkey> = Some(ctx.accounts.mint_authority.key());
        let data: DataV2 = DataV2 {
            name: ("superNFT").to_string(),
            symbol: ("SMB").to_string(),
            uri: ("abc.com").to_string(),
            seller_fee_basis_points: 1000,
            creators: None,
            collection: None,
            uses: None,
        };

        mpl_token_metadata::instruction::update_metadata_accounts_v2(
            program_id,
            metadata_account,
            update_authority,
            new_update_authority,
            Some(data),
            Some(false),
            Some(true),
        );
        
        Ok(())
    }

2 Answers 2

0

This does seams the right way you have to invoke the CPI as well like this :-

 program::invoke_signed(
    &update_ix,
    &[
        ctx.accounts.metadata.to_account_info(),
        ctx.accounts.update_auth.to_account_info(),
    ],
   pda_signer,
)?;

Let me you if you get any error message

0

you don't need to do it on your finger. candy machine v2 supports create & update nft. and it's very easy to use.

please reference this.

https://github.com/metaplex/metaplex

in this case, we've used candy machine to mint and update nft. please contact me if you've got a problem.

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.