Solana programs Part 3: understanding Metaplex Token Metadata
May 23, 2022

The metaplex-token-metadata program is the backbone of NFT on Solana.

Imagine you’d like to create an NFT for your art, essentially you need to:

  1. upload your art (digitized) to a permanent storage
  2. create a token mint (i.e., a unique identifier) for your art on Solana
  3. mint one token owned by your wallet

In Step 2, the token mint is special — its supply is only one and it must be associated with information of your art (e.g., name, creator, where it is, etc).

Metaplex has created a specification for such “metadata”, which can be added to every (special) token mint by the token-metadata program.

In this article, we elaborate on the implementation details of token-metadata.

An NFT created on Metaplex

How to Mint NFT with Token Metadata?

The token-metadata program has a good number of instructions (more than 20 in total). The following four are the most commonly used:

  • MetadataInstruction::CreateMetadataAccountV2
  • MetadataInstruction::CreateMasterEditionV3
  • MetadataInstruction::MintNewEditionFromMasterEditionViaToken
  • MetadataInstruction::UpdateMetadataAccountV2
A transaction log on the token-metadata program

1. CreateMetadataAccountV2

First, create a metadata account by calling function process_create_metadata_accounts_v2 :

Note: Every metadata account is a PDA with the token mint (mint_info) as a part of the seeds:

The mint authority (mint_authority_info ) must be a signer.

The Metadata struct has ten fields:

The function basically initializes each field, e.g., metadata.mint, metadata.update_authority and metadata.data :

The metadata.data records the NFT’s attributes (e.g., name, uri and creators):

This metadata account will serve as the master_metadata of the NFT.

2. CreateMasterEditionV3

Then, create a master edition account of the NFT, so that you can use it to print multiple editions (e.g., a limited supply of 10) of your NFT later.

The function process_create_master_edition is used to create a master edition account (edition_account_info ) for a token mint given a max_supply :

Note1: Every master edition account is a PDA with the token mint (mint_info) as a part of the seeds:

Note2: The function can only be called once for a token mint by the update_authority of the token metadata, and only if the supply on the mint is one:

The MasterEdition record has three fields:

pub struct MasterEditionV2 {
pub key: Key,
pub supply: u64,
pub max_supply: Option,}


The function basically initializes these fields:

Finally, it transfers the authority of the token mint (AuthorityType::MintTokensand AuthorityType::FreezeAccount ) to the master edition account:

After that, other token mints may become editions of this metadata, representing limited editions of the NFT.

3. MintNewEditionFromMasterEditionViaToken

The function process_mint_new_edition_from_master_edition_via_token is used to mint new editions of an NFT from its master edition:

The caller provides a new mint account and an edition number, and must be signer of the master_metadata.mint’s token account (i.e., an owner of the NFT):

The function will create a new edition_marker PDA using the edition number and the NFT’s mint (master_metadata.mint) as a part of the seeds:

Then, the function mint_limited_edition is called to mint the new edition:

In mint_limited_edition , a new metadata account will be created based on the new mint account (mint_info):

The new mint must be different from master_metadata.mint and its supply must be one:

The new mint account is also part of the seeds for creating the new edition PDA:

Finally, similar to that in CreateMasterEditionV3 , the new mint account’s authority (AuthorityType::MintTokens and AuthorityType::FreezeAccount ) is set to the new edition account:

4. UpdateMetadataAccountV2

The function process_update_metadata_accounts_v2 can be used to update the metadata at any time by the metadata’s update_authority:

To update the metadata.data record, metadata.is_mutable must be true :

The metadata’s update_authority can also be updated, as well as metadata.primary_sale_happened :

Other Token Metadata instructions

The token-metadata program has several other functionalities such as verifying the NFT creators (see full code):

MetadataInstruction::SignMetadata => {
    msg!(“Instruction: Sign Metadata”);
    process_sign_metadata(program_id, accounts)}
MetadataInstruction::RemoveCreatorVerification => {
    msg!("Instruction: Remove Creator Verification");
    process_remove_creator_verification(program_id, accounts)}

In the next few articles, we will continue to highlight the technical details of a few more popular Solana programs.


Sec3 (formerly Soteria) Auto Auditor Software and Security Audit Service

Sec3 is founded by leading minds in the fields of blockchain security and software verification.

We are pleased to provide an automatic security scanner software and security audit services to high-impact Dapps on Solana. Please visit Sec3.dev for more information.