I am trying to update NFT metadata using mpl-token-metadata 5.1.0. But I can't find the function like update_metadata_accounts_v2() in docs. I am using anchor version 0.29.0, Solana-cli 1.18.16, mpl-token-metadata 5.1.0. Where can I get resource for this work? Thank you.
1 Answer
You can check out all available instructions in the docs, via https://docs.rs/mpl-token-metadata/latest/mpl_token_metadata/instructions/index.html
In particular, you are interested in the UpdateAsUpdateAuthorityV2
instruction builder
pub fn update_metadata(
ctx: Context<UpdateMetadata>,
name: String,
symbol: String,
uri: String,
seller_fee_basis_points: u16,
) -> Result<()> {
let data = Data {
name,
symbol,
uri,
seller_fee_basis_points,
creators: None, //! update with creators if needed
};
UpdateAsUpdateAuthorityV2CpiBuilder::new(&ctx.accounts.metadata_program.to_account_info())
.authority(&ctx.accounts.authority.to_account_info())
.mint(&ctx.accounts.mint.to_account_info())
.metadata(&ctx.accounts.metadata_account)
.payer(&ctx.accounts.authority)
.system_program(&ctx.accounts.system_program)
.sysvar_instructions(&ctx.accounts.sysvar_instruction.to_account_info())
.data(data)
.invoke()?;
Ok(())
}
Accounts required for this
#[derive(Accounts)]
pub struct UpdateMetadata<'info> {
#[account(mut)]
pub authority: Signer<'info>,
#[account(mut)]
pub mint: Account<'info, Mint>,
/// CHECK:
#[account(mut)]
pub metadata_account: Account<'info, MetadataAccount>,
pub metadata_program: Program<'info, Metadata>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
/// CHECK: ok
pub sysvar_instruction: UncheckedAccount<'info>,
}
edit: removed data being passed in as struct and using parameters defined in the Data struct
-
Thank you for your kind explanation. But, I wanna update NFT metadata uri. Could you let me know about this part? Commented Nov 25 at 13:19
-
-
But there is also bug in accounts context. Could you let me know about the sysvar_instruction? Commented Nov 26 at 9:07
-
sysvar are read-only accounts that give us information about the network. instructions sysvar contain the serialized instructions in a Message while that Message is being processed, ref from docs– JimiiCommented Nov 26 at 10:14
-