> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Metaplex Metadata

> Learn how to add metadata to SPL Tokens using the Metaplex Token Metadata Program.

Standard SPL Tokens don't include metadata like a name, symbol, or image. The
[Metaplex Token Metadata Program](https://developers.metaplex.com/token-metadata)
solves this by creating a metadata account linked to each token mint.

<Info>
  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](/developers/docs/tokens/extensions/metadata) which
  stores metadata directly on the mint account.
</Info>

## How Token Metadata Works

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.).

```text
┌─────────────────┐       ┌─────────────────────┐
│   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:

```bash Terminal
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](/developers/docs/intro/installation/surfpool-cli-basics) fetches the
programs and accounts your transactions use from mainnet on demand:

```bash Terminal
surfpool start
```

With the Solana CLI's test validator, clone the program when it starts:

```bash Terminal
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`.

## Create Token with Metadata

The `createV1` instruction creates both the mint account and its metadata in a
single transaction.

### Typescript

<CodeGroup>

```ts Kit
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);
```

```ts title="Kit Helper"
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);
```

</CodeGroup>

## Fetch Token Metadata

To learn how to fetch metadata for existing tokens, see the
[Fetch Token Metadata](/developers/cookbook/tokens/fetch-token-metadata)
cookbook recipe.

## Update Token Metadata

The update authority can modify the metadata if the account is mutable.

```ts Kit
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:

| Standard                         | Description                                | Use Case            |
| -------------------------------- | ------------------------------------------ | ------------------- |
| `Fungible`                       | Standard fungible token with metadata      | Currencies, points  |
| `FungibleAsset`                  | Fungible token representing a unique asset | Semi-fungible items |
| `NonFungible`                    | NFT with Master Edition                    | 1/1 artwork         |
| `ProgrammableNonFungible`        | NFT with enforced royalties                | Creator royalties   |
| `NonFungibleEdition`             | Printed copy of an NFT                     | Limited editions    |
| `ProgrammableNonFungibleEdition` | Printed copy with enforced royalties       | Limited editions    |

```ts
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;
```

## Offchain Metadata Format

The `uri` field points to a JSON file containing extended metadata. The standard
format follows the
[Metaplex Token Metadata Standard](https://developers.metaplex.com/token-metadata/token-standard):

```json token-metadata.json
{
  "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"
      }
    ]
  }
}
```

<Danger>
  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.
</Danger>

## Metadata Account Structure

The onchain metadata account stores a `Metadata` struct, with the name,
symbol, URI, royalties, and creators nested in a `Data` struct
([source](https://github.com/metaplex-foundation/mpl-token-metadata/blob/0236c068fca3e3a8fb7d9e8057da58ba010af05d/programs/token-metadata/program/src/state/metadata.rs#L68-L95)):

```rust
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

1. **Set appropriate mutability**: Use `isMutable: false` for tokens that should
   never change
2. **Use reliable URI hosting**: Offchain metadata should be on permanent
   storage
3. **Verify creators**: Creator addresses should be verified to confirm
   authenticity
4. **Consider royalties**: Set `sellerFeeBasisPoints` for secondary sale
   royalties (marketplaces may or may not enforce these)
