Standard SPL Tokens don’t include metadata like a name, symbol, or image. The
Metaplex Token Metadata Program
solves this by creating a metadata account linked to each token mint.
This guide covers the Metaplex Token Metadata Program which can be used for
standard SPL Tokens and Token-2022. To use the Token-2022 Metadata Extension,
see the Metadata Extension guide which
stores metadata directly on the mint account.
The Token Metadata Program creates a program-derived address (PDA) for each
token mint. This metadata account stores onchain information like the token’s
name and symbol, plus a URI pointing to offchain JSON metadata (images,
descriptions, etc.).
┌─────────────────┐ ┌─────────────────────┐
│ Mint Account │ │ Metadata Account │
│ │ │ (PDA) │
│ - Supply │◄──────│ - Name │
│ - Decimals │ │ - Symbol │
│ - Authority │ │ - URI │
└─────────────────┘ │ - Seller Fee │
│ - Creators │
└─────────────────────┘
The metadata PDA is derived from seeds: ["metadata", program_id, mint_address]
Setup
The examples on this page use @solana/kit and the Metaplex Token Metadata
Kit client:
npm install @solana/kit @solana-program/token @metaplex-foundation/mpl-token-metadata-kit
@metaplex-foundation/mpl-token-metadata-kit 0.0.3 loads
@solana-program/token at runtime without listing it as a dependency, so
install it as well. The Metaplex client is also built on @solana/kit 6, and
npm installs a second copy of Kit for it. The two copies’ RPC types don’t
match, so the update example reads the metadata account with Kit’s
fetchEncodedAccount and decodes it with decodeMetadata instead of passing
rpc to fetchMetadata. The examples also call
assertIsTransactionWithBlockhashLifetime before sending, which
sendAndConfirmTransactionFactory needs to type-check.
The examples send transactions to a local validator at http://127.0.0.1:8899.
A plain local validator doesn’t include the Token Metadata program, so start
one that loads it from mainnet.
Surfpool fetches the
programs and accounts your transactions use from mainnet on demand:
With the Solana CLI’s test validator, clone the program when it starts:
solana-test-validator --clone-upgradeable-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s --url mainnet-beta
The examples sign with your default Solana CLI keypair
(~/.config/solana/id.json), which pays for the transactions and becomes the
token’s update authority. If you don’t have one, create it with
solana-keygen new.
The createV1 instruction creates both the mint account and its metadata in a
single transaction.
Typescript
import {
airdropFactory,
appendTransactionMessageInstructions,
assertIsTransactionWithBlockhashLifetime,
createKeyPairSignerFromBytes,
createSolanaRpc,
createSolanaRpcSubscriptions,
createTransactionMessage,
generateKeyPairSigner,
lamports,
pipe,
sendAndConfirmTransactionFactory,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners
} from "@solana/kit";
import { readFile } from "node:fs/promises";
import { homedir } from "node:os";
import {
getCreateV1InstructionAsync,
TokenStandard
} from "@metaplex-foundation/mpl-token-metadata-kit";
// Create connection
const rpc = createSolanaRpc("http://127.0.0.1:8899");
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://127.0.0.1:8900");
// Load the default CLI keypair. It pays for the transaction and becomes the
// update authority, so the update example below can sign with it.
const payer = await createKeyPairSignerFromBytes(
new Uint8Array(
JSON.parse(await readFile(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
const mint = await generateKeyPairSigner();
// Fund payer (local validator)
await airdropFactory({ rpc, rpcSubscriptions })({
recipientAddress: payer.address,
lamports: lamports(1_000_000_000n),
commitment: "confirmed"
});
// Create fungible token with metadata
const createInstruction = await getCreateV1InstructionAsync({
mint,
authority: payer,
payer,
name: "My Token",
symbol: "MTK",
uri: "https://example.com/token.json",
sellerFeeBasisPoints: 0,
tokenStandard: TokenStandard.Fungible
});
// Build and send transaction
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
const transactionMessage = pipe(
createTransactionMessage({ version: 0 }),
(tx) => setTransactionMessageFeePayerSigner(payer, tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => appendTransactionMessageInstructions([createInstruction], tx)
);
const signedTransaction =
await signTransactionMessageWithSigners(transactionMessage);
assertIsTransactionWithBlockhashLifetime(signedTransaction);
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(
signedTransaction,
{ commitment: "confirmed" }
);
console.log("Mint Address:", mint.address);
import {
airdropFactory,
appendTransactionMessageInstructions,
assertIsTransactionWithBlockhashLifetime,
createKeyPairSignerFromBytes,
createSolanaRpc,
createSolanaRpcSubscriptions,
createTransactionMessage,
generateKeyPairSigner,
lamports,
pipe,
sendAndConfirmTransactionFactory,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners
} from "@solana/kit";
import { readFile } from "node:fs/promises";
import { homedir } from "node:os";
import { createFungible } from "@metaplex-foundation/mpl-token-metadata-kit";
// Create connection
const rpc = createSolanaRpc("http://127.0.0.1:8899");
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://127.0.0.1:8900");
// Load the default CLI keypair. It pays for the transaction and becomes the
// update authority, so the update example below can sign with it.
const payer = await createKeyPairSignerFromBytes(
new Uint8Array(
JSON.parse(await readFile(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
const mint = await generateKeyPairSigner();
// Fund payer (local validator)
await airdropFactory({ rpc, rpcSubscriptions })({
recipientAddress: payer.address,
lamports: lamports(1_000_000_000n),
commitment: "confirmed"
});
// Use the createFungible helper for simpler API
const createInstruction = await createFungible({
mint,
authority: payer,
payer,
name: "My Token",
symbol: "MTK",
uri: "https://example.com/token.json",
sellerFeeBasisPoints: 0
});
// Build and send transaction
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
const transactionMessage = pipe(
createTransactionMessage({ version: 0 }),
(tx) => setTransactionMessageFeePayerSigner(payer, tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => appendTransactionMessageInstructions([createInstruction], tx)
);
const signedTransaction =
await signTransactionMessageWithSigners(transactionMessage);
assertIsTransactionWithBlockhashLifetime(signedTransaction);
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(
signedTransaction,
{ commitment: "confirmed" }
);
console.log("Mint Address:", mint.address);
To learn how to fetch metadata for existing tokens, see the
Fetch Token Metadata
cookbook recipe.
The update authority can modify the metadata if the account is mutable.
import {
address,
appendTransactionMessageInstructions,
assertAccountExists,
assertIsTransactionWithBlockhashLifetime,
createKeyPairSignerFromBytes,
createSolanaRpc,
createSolanaRpcSubscriptions,
createTransactionMessage,
fetchEncodedAccount,
pipe,
sendAndConfirmTransactionFactory,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners
} from "@solana/kit";
import { readFile } from "node:fs/promises";
import { homedir } from "node:os";
import {
decodeMetadata,
findMetadataPda,
getUpdateV1InstructionAsync
} from "@metaplex-foundation/mpl-token-metadata-kit";
const rpc = createSolanaRpc("http://127.0.0.1:8899");
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://127.0.0.1:8900");
// Load the update authority as a KeyPairSigner (here, the default CLI keypair).
// It must be the wallet that created the token and it must hold some SOL.
const authority = await createKeyPairSignerFromBytes(
new Uint8Array(
JSON.parse(await readFile(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
// Replace with the address of a mutable token whose update authority is this
// keypair, for example one you created with the create example above.
const mintAddress = address("YOUR_MINT_ADDRESS");
// Fetch current metadata to preserve existing values
const [metadataAddress] = await findMetadataPda({ mint: mintAddress });
const metadataAccount = await fetchEncodedAccount(rpc, metadataAddress);
assertAccountExists(metadataAccount);
const currentMetadata = decodeMetadata(metadataAccount);
// Update metadata (must provide all data fields)
const updateInstruction = await getUpdateV1InstructionAsync({
mint: mintAddress,
authority, // Update authority signer
payer: authority,
data: {
name: "Updated Token Name",
symbol: "UPD",
uri: "https://example.com/updated-token.json",
sellerFeeBasisPoints: 100, // 1%
creators:
currentMetadata.data.creators.__option === "Some"
? currentMetadata.data.creators.value
: null
}
});
// Build and send transaction
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
const transactionMessage = pipe(
createTransactionMessage({ version: 0 }),
(tx) => setTransactionMessageFeePayerSigner(authority, tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => appendTransactionMessageInstructions([updateInstruction], tx)
);
const signedTransaction =
await signTransactionMessageWithSigners(transactionMessage);
assertIsTransactionWithBlockhashLifetime(signedTransaction);
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(
signedTransaction,
{ commitment: "confirmed" }
);
console.log("Metadata updated successfully");
Token Standards
The Token Metadata Program supports different token standards:
import { TokenStandard } from "@metaplex-foundation/mpl-token-metadata-kit";
// For fungible tokens
tokenStandard: TokenStandard.Fungible;
// For NFTs
tokenStandard: TokenStandard.NonFungible;
// For programmable NFTs (enforced royalties)
tokenStandard: TokenStandard.ProgrammableNonFungible;
The uri field points to a JSON file containing extended metadata. The standard
format follows the
Metaplex Token Metadata Standard:
{
"name": "My Token",
"symbol": "MTK",
"description": "A description of the token",
"image": "https://example.com/token-image.png",
"external_url": "https://example.com",
"attributes": [
{
"trait_type": "Category",
"value": "Utility"
}
],
"properties": {
"files": [
{
"uri": "https://example.com/token-image.png",
"type": "image/png"
}
]
}
}
Store your metadata JSON on a reliable, permanent storage solution like
Arweave, IPFS, or a dedicated CDN. If the URI becomes inaccessible, wallets
and explorers won’t be able to display your token’s metadata.
The onchain metadata account stores a Metadata struct, with the name,
symbol, URI, royalties, and creators nested in a Data struct
(source):
pub struct Metadata {
pub key: Key, // Account type identifier
pub update_authority: Pubkey, // Can update metadata
pub mint: Pubkey, // Associated mint
pub data: Data, // Name, symbol, URI, royalties, creators
pub primary_sale_happened: bool, // Primary sale flag
pub is_mutable: bool, // Can metadata be updated
pub edition_nonce: Option<u8>, // Edition nonce
pub token_standard: Option<TokenStandard>, // Token type
pub collection: Option<Collection>, // Collection info
pub uses: Option<Uses>, // Use tracking
pub collection_details: Option<CollectionDetails>, // Collection size (collection NFTs)
pub programmable_config: Option<ProgrammableConfig>, // Rule set (programmable NFTs)
}
pub struct Data {
pub name: String, // Token name (max 32 chars)
pub symbol: String, // Token symbol (max 10 chars)
pub uri: String, // URI to offchain JSON (max 200 chars)
pub seller_fee_basis_points: u16, // Royalty % (100 = 1%)
pub creators: Option<Vec<Creator>>, // Creator list with shares
}
Best Practices
- Set appropriate mutability: Use
isMutable: false for tokens that should
never change
- Use reliable URI hosting: Offchain metadata should be on permanent
storage
- Verify creators: Creator addresses should be verified to confirm
authenticity
- Consider royalties: Set
sellerFeeBasisPoints for secondary sale
royalties (marketplaces may or may not enforce these)