updateMetadataAccountV2 static method

TransactionInstruction updateMetadataAccountV2({
  1. required Pubkey metadata,
  2. required Pubkey updateAuthority,
  3. DataV2? dataV2,
  4. Pubkey? newUpdateAuthority,
  5. bool? primarySaleHappened,
  6. bool? isMutable,
})

This instruction enables us to update parts of the Metadata account. Note that some fields have constraints limiting how they can be updated. For instance, once the isMutable field is set to false, it cannot be changed back to true.

Keys:

  • [w] metadata - Metadata key (pda of: 'metadata', program id, mint id).
  • [s] updateAuthority - Update authority info.

Data:

  • dataV2

    name - The on-chain name of the token, limited to 32 bytes. For instance "Degen Ape #1 ".

    symbol - The on-chain symbol of the token, limited to 10 bytes. For instance "DAPE".

    uri - The URI of the token, limited to 200 bytes. This URI points to an off-chain JSON file that contains additional data following a certain standard. You can learn more about this JSON standard here. The JSON file can either be stored in a traditional server (e.g. using AWS) or using a permanent storage solution such as using Arweave.

    sellerFeeBasisPoints - The royalties shared by the creators in basis points — i.e. 550 means 5.5%. Whilst this field is used by virtually all NFT marketplaces, it is not enforced by the Token Metadata program itself.

    creators - An array of creators and their share of the royalties. This array is limited to 5 creators. Note that, because the Creators field is an array of variable length, we cannot guarantee the byte position of any field that follows.

    collection - This field optionally links to the Mint address of another NFT that acts as a Collection NFT.

    uses - This field can make NFTs usable. Meaning you can load it with a certain amount of "uses" and use it until it has run out. You can learn more about using NFTs here.

  • newUpdateAuthority - The public key that is allowed to update this account.

  • primarySaleHappened - A boolean indicating if the token has already been sold at least once. Once flipped to true, it cannot ever be False again. This field can affect the way royalties are distributed.

  • isMutable - A boolean indicating if the Metadata Account can be updated. Once flipped to false, it cannot ever be true again.

Implementation

static TransactionInstruction updateMetadataAccountV2({
  // Keys
  required final Pubkey metadata,
  required final Pubkey updateAuthority,
  // Data
  final DataV2? dataV2,
  final Pubkey? newUpdateAuthority,
  final bool? primarySaleHappened,
  final bool? isMutable,
}) {
  final List<AccountMeta> keys = [
    AccountMeta.writable(metadata),
    AccountMeta.signer(updateAuthority),
  ];

  final booleanOption = borsh.boolean.option();
  final List<Iterable<u8>> data = [
    dataV2 != null ? const [1] : const [0], // Option flag
    if (dataV2 != null) [
      ...metadataNameCodec.encode(dataV2.name),
      ...metadataSymbolCodec.encode(dataV2.symbol),
      ...metadataUriCodec.encode(dataV2.uri),
      ...metadataSellerFeeBasisPointsCodec.encode(dataV2.sellerFeeBasisPoints),
      ...metadataCreatorsCodec.encode(dataV2.creators?.toJson()),
      ...metadataCollectionCodec.encode(dataV2.collection?.toJson()),
      ...metadataUsesCodec.encode(dataV2.uses?.toJson()),
    ],
    borsh.pubkey.option().encode(newUpdateAuthority?.toBase58()),
    booleanOption.encode(primarySaleHappened),
    booleanOption.encode(isMutable),
  ];

  return _instance.createTransactionIntruction(
    MetaplexTokenMetadataInstruction.updateMetadataAccountV2,
    keys: keys,
    data: data,
  );
}