Skip to content

​What Are Metadata Pointer and Token Metadata Extensions?

The Token Extension Program’s MetadataPointer mint extension stores two fields on a mint:
  • An authority that can update the pointer
  • The address of the account that stores the token’s metadata
That pointer can reference any account owned by a program implementing the token-metadata interface. The Token Extension Program also implements that same interface directly through the TokenMetadata mint extension. With TokenMetadata, the mint stores the token’s name, symbol, uri, update_authority, and custom metadata on the mint account itself.
Offchain Metadata URIThe uri field points to offchain JSON metadata. See Offchain Metadata Format.
The two extensions solve different problems:
  • MetadataPointer specifies the account that stores metadata.
  • TokenMetadata stores the metadata directly on the mint account.
Variable Length ExtensionTokenMetadata is a variable length TLV extension. InitializeTokenMetadata, UpdateField, and RemoveKey can resize the mint account data, but they do not transfer additional lamports. The mint account needs enough lamports to remain rent-exempt for the metadata being stored. If the metadata grows later, additional lamports need to be transferred to the mint account before the instruction that resizes it.

​Before you start

The examples on this page run against a local validator at http://localhost:8899 (WebSocket ws://localhost:8900) and fund their accounts with airdrops from it. Start one in a separate terminal with Surfpool (surfpool start) or solana-test-validator. Each code section below lists the packages or crates it needs. The TypeScript examples use top-level await, so run them as ES modules, for example with npx tsx index.ts in a project whose package.json sets "type": "module".

​How to Store Token Metadata on the Mint Account

To store metadata on the mint account:
  1. Calculate the mint account size and rent needed for the mint, extensions, and metadata.
  2. Create the mint account with CreateAccount, initialize MetadataPointer, and initialize the mint with InitializeMint.
  3. Initialize TokenMetadata on the mint account, then use UpdateField to add or update metadata.
  4. Use RemoveKey, UpdateAuthority, and Emit to remove custom metadata, change or clear the update authority, or return the current metadata in transaction return data.
1

Calculate account size

Calculate the mint account size for the base mint plus the MetadataPointer extension. This is the size used in CreateAccount.
Example
2

Calculate rent

Calculate rent using the maximum size needed after TokenMetadata is stored on the mint.
Example
3

Create the mint account

Create the mint account with the calculated space and lamports.
Example
4

Initialize MetadataPointer

Initialize MetadataPointer and set its metadata address to the mint address.
Example
5

Initialize the mint

Initialize the mint with InitializeMint in the same transaction.
Example
6

Initialize and update metadata

Initialize TokenMetadata on the mint. Use UpdateField to add custom metadata; if the field does not exist, UpdateField adds it.
Example
7

Update, remove, or emit metadata

After the mint is initialized, use UpdateField to update metadata, UpdateMetadataPointer to update the metadata pointer, RemoveKey to remove custom metadata, UpdateAuthority to clear the update authority, and Emit to return the current metadata.
Example
Instruction OrderMetadataPointerInstruction::Initialize must come before InitializeMint. CreateAccount, MetadataPointerInstruction::Initialize, and InitializeMint must be included in the same transaction.

​Source Reference

​Metadata Pointer

ItemDescriptionSource
MetadataPointerMint extension that stores the metadata pointer authority and the metadata account address.Source
MetadataPointerInstruction::InitializeInitializes the metadata pointer extension before InitializeMint.Source
MetadataPointerInstruction::UpdateUpdates the metadata address stored by the mint’s metadata pointer extension.Source
process_initialize (MetadataPointer)Metadata pointer processor logic that requires at least an authority or a metadata address during initialization.Source
process_update (MetadataPointer)Validates the metadata pointer authority, then rewrites the mint’s stored metadata address.Source

​Token Metadata

ItemDescriptionSource
TokenMetadataVariable-length token-metadata interface state stored in a TLV entry.Source
FieldField enum used by UpdateField to target name, symbol, uri, or a custom key.Source
TokenMetadataInstruction::InitializeInitializes the base name, symbol, and uri fields for a token-metadata account.Source
TokenMetadataInstruction::UpdateFieldAdds or updates a base field or custom metadata field on the token metadata.Source
TokenMetadataInstruction::RemoveKeyRemoves a custom metadata key. Base fields cannot be removed with this instruction.Source
TokenMetadataInstruction::UpdateAuthorityRotates the metadata update authority, or clears it entirely to make metadata immutable.Source
TokenMetadataInstruction::EmitReturns the serialized metadata through transaction return data, optionally for a byte range.Source
process_initialize (TokenMetadata)Token-metadata processor logic that requires the metadata account to be the mint itself and the mint to have MetadataPointer.Source
process_update_fieldReallocates and rewrites the variable length TokenMetadata TLV entry after a field update.Source
process_remove_keyValidates the update authority, removes a custom metadata key, and rewrites the TLV entry.Source
process_update_authorityValidates the current update authority, then rotates or clears the metadata authority in place.Source
process_emitReads the serialized TokenMetadata from the mint and writes the requested slice to return data.Source

​Kit

These examples use the generated Token-2022 instructions directly.
Terminal
Instructions

​Web3.js v3

These examples use the class-based @solana/web3.js v3 API with @solana-program instruction builders.
Terminal
Instructions

​Rust

Add these dependencies to Cargo.toml (tested with Rust 1.89, 1.98, and 1.99):
Cargo.toml
Rust

​Web3.js (legacy)

These examples use legacy @solana/web3.js with @solana/spl-token and @solana/spl-token-metadata.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
Terminal
Instructions