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

# How to Create a Token with Metadata

> Learn how to create an SPL Token with onchain metadata using the Metaplex Token Metadata Program.

To add metadata (name, symbol, image) to a standard SPL Token, you need to use
the
[Metaplex Token Metadata Program](https://developers.metaplex.com/token-metadata).
This creates a metadata account that is linked to your token mint via a Program
Derived Address (PDA).

<Info>
  This guide covers metadata for standard SPL Tokens (Token Program) and is also
  applicable for Token-2022. If you want to use the Metadata Extension for
  Token-2022, see the [Metadata Extension
  guide](/developers/docs/tokens/extensions/metadata).
</Info>

The Kit examples use the Metaplex Token Metadata client. Install it together
with `@solana-program/token`, which the client loads but doesn't declare as a
dependency:

```shell
npm install @solana/kit @solana/kit-plugin-rpc @solana/kit-plugin-signer @metaplex-foundation/mpl-token-metadata-kit @solana-program/token
```

<Note>
  `@metaplex-foundation/mpl-token-metadata-kit` 0.0.3 is built on Kit 6. It
  runs with Kit 8, but TypeScript reports the RPC types as incompatible until
  you resolve it onto your Kit version in `package.json`, then delete
  `node_modules` and `package-lock.json` and run `npm install` again:

  ```json
  "overrides": {
    "@metaplex-foundation/mpl-token-metadata-kit": {
      "@solana/kit": "$@solana/kit",
      "@solana/program-client-core": "^8.6.0"
    }
  }
  ```
</Note>

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
import { createClient, generateKeyPairSigner, lamports } from "@solana/kit";
import { rpcAirdrop, solanaRpc } from "@solana/kit-plugin-rpc";
import { airdropPayer, payer as kitPayer } from "@solana/kit-plugin-signer";
import {
  getCreateV1InstructionAsync,
  fetchMetadataFromSeeds,
  TokenStandard,
} from "@metaplex-foundation/mpl-token-metadata-kit";

const payer = await generateKeyPairSigner();
const mint = await generateKeyPairSigner();

const client = await createClient()
  .use(kitPayer(payer))
  .use(
    solanaRpc({
      rpcUrl: "http://localhost:8899",
      rpcSubscriptionsUrl: "ws://localhost:8900",
    }),
  )
  .use(rpcAirdrop())
  .use(airdropPayer(lamports(1_000_000_000n)));

// Create token with metadata
const createInstruction = await getCreateV1InstructionAsync({
  mint,
  authority: payer,
  payer,
  name: "My Token",
  symbol: "MTK",
  uri: "https://example.com/token-metadata.json",
  sellerFeeBasisPoints: 0, // 0% royalty (use 500 for 5%)
  tokenStandard: TokenStandard.Fungible,
});

const { context } = await client.sendTransaction([createInstruction]);
console.log("Transaction Signature:", context.signature);

// Verify metadata was created
const metadata = await fetchMetadataFromSeeds(client.rpc, {
  mint: mint.address,
});

console.log("Mint Address:", mint.address);
console.log("Token Name:", metadata.data.name);
console.log("Token Symbol:", metadata.data.symbol);
console.log("Metadata URI:", metadata.data.uri);
```

<div className="sol-run" data-run="cookbook/tokens/create-token-with-metadata/create" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature: KMKH8L6a3JVrk9qNHHUk4GdakGKKnNBPzSra8bLJ5eRgA5MJz3x5n978eCYpyyvo3cB4HEyVE4tnJ48UVa8k2MU
Mint Address: JDbxowdb6d7JLJMb15VeV2fmd96dzX43txGGvM9Fh7kp
Token Name: My Token
Token Symbol: MTK
Metadata URI: https://example.com/token-metadata.json
```

</div>
</div>

</Tab>
<Tab title="Python">
<div className="sol-tab-label">Python</div>

```py
import asyncio
import struct

from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed
from solders.instruction import AccountMeta, Instruction
from solders.keypair import Keypair
from solders.message import MessageV0
from solders.pubkey import Pubkey
from solders.system_program import ID as SYSTEM_PROGRAM_ID
from solders.sysvar import INSTRUCTIONS
from solders.transaction import VersionedTransaction
from spl.token.constants import TOKEN_PROGRAM_ID

METADATA_PROGRAM_ID = Pubkey.from_string("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")


async def main():
    async with AsyncClient("http://localhost:8899", commitment=Confirmed) as client:
        payer = Keypair()
        mint = Keypair()

        airdrop = await client.request_airdrop(payer.pubkey(), 1_000_000_000)
        await client.confirm_transaction(airdrop.value)

        metadata, _ = Pubkey.find_program_address(
            [b"metadata", bytes(METADATA_PROGRAM_ID), bytes(mint.pubkey())],
            METADATA_PROGRAM_ID,
        )

        # CreateV1 creates the mint and its metadata account in one instruction.
        data = bytes([42, 0])  # CreateV1
        for value in ["My Token", "MTK", "https://example.com/token-metadata.json"]:
            data += struct.pack("<I", len(value)) + value.encode()  # name, symbol, uri
        data += struct.pack("<H", 0)  # seller fee basis points (0% royalty)
        # creators: none, primary sale happened: false, is mutable: true,
        # token standard: Fungible, collection, uses, collection details, rule set: none,
        # decimals: 9, print supply: none
        data += bytes([0, 0, 1, 2, 0, 0, 0, 0, 1, 9, 0])

        create_instruction = Instruction(
            METADATA_PROGRAM_ID,
            data,
            [
                AccountMeta(metadata, is_signer=False, is_writable=True),
                AccountMeta(METADATA_PROGRAM_ID, is_signer=False, is_writable=False),  # no master edition
                AccountMeta(mint.pubkey(), is_signer=True, is_writable=True),
                AccountMeta(payer.pubkey(), is_signer=True, is_writable=False),  # mint authority
                AccountMeta(payer.pubkey(), is_signer=True, is_writable=True),  # payer
                AccountMeta(payer.pubkey(), is_signer=True, is_writable=False),  # update authority
                AccountMeta(SYSTEM_PROGRAM_ID, is_signer=False, is_writable=False),
                AccountMeta(INSTRUCTIONS, is_signer=False, is_writable=False),
                AccountMeta(TOKEN_PROGRAM_ID, is_signer=False, is_writable=False),
            ],
        )

        blockhash = (await client.get_latest_blockhash()).value.blockhash
        message = MessageV0.try_compile(payer.pubkey(), [create_instruction], [], blockhash)
        transaction = VersionedTransaction(message, [payer, mint])

        signature = (await client.send_transaction(transaction)).value
        print("Transaction Signature:", signature)
        print("Mint Address:", mint.pubkey())


asyncio.run(main())
```

<div className="sol-run" data-run="cookbook/tokens/create-token-with-metadata/create" data-tab="Python">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature: 3GSoCKq9SXG9Sgj2mQxco4iVvxSiLba917dHoJZf5fVksx6pfQJqWJgtAWUirgtuGBd2ezecsvuXqH8iMt1xc6Mg
Mint Address: uNRwEopCVwoctChxzkf4w9kn9Ekq6TCHTJ2hnJ6Kybm
```

</div>
</div>

</Tab>
<Tab title="Go">
<div className="sol-tab-label">Go</div>

```go
package main

import (
	"context"
	"encoding/binary"
	"fmt"
	"time"

	"github.com/solana-foundation/solana-go/v2"
	"github.com/solana-foundation/solana-go/v2/rpc"
)

func main() {
	ctx := context.Background()
	client := rpc.New("http://localhost:8899")

	payer := solana.NewWallet()
	mint := solana.NewWallet()

	_, err := client.RequestAirdrop(ctx, payer.PublicKey(), solana.LAMPORTS_PER_SOL, rpc.CommitmentConfirmed)
	if err != nil {
		panic(err)
	}
	time.Sleep(2 * time.Second)

	metadata, _, err := solana.FindTokenMetadataAddress(mint.PublicKey())
	if err != nil {
		panic(err)
	}

	// CreateV1 creates the mint and its metadata account in one instruction.
	data := []byte{42, 0} // CreateV1
	for _, value := range []string{"My Token", "MTK", "https://example.com/token-metadata.json"} {
		data = binary.LittleEndian.AppendUint32(data, uint32(len(value))) // name, symbol, uri
		data = append(data, value...)
	}
	data = binary.LittleEndian.AppendUint16(data, 0) // seller fee basis points (0% royalty)
	// creators: none, primary sale happened: false, is mutable: true,
	// token standard: Fungible, collection, uses, collection details, rule set: none,
	// decimals: 9, print supply: none
	data = append(data, 0, 0, 1, 2, 0, 0, 0, 0, 1, 9, 0)

	createInstruction := solana.NewInstruction(
		solana.TokenMetadataProgramID,
		solana.AccountMetaSlice{
			solana.Meta(metadata).WRITE(),
			solana.Meta(solana.TokenMetadataProgramID), // no master edition
			solana.Meta(mint.PublicKey()).WRITE().SIGNER(),
			solana.Meta(payer.PublicKey()).SIGNER(),         // mint authority
			solana.Meta(payer.PublicKey()).WRITE().SIGNER(), // payer
			solana.Meta(payer.PublicKey()).SIGNER(),         // update authority
			solana.Meta(solana.SystemProgramID),
			solana.Meta(solana.SysVarInstructionsPubkey),
			solana.Meta(solana.TokenProgramID),
		},
		data,
	)

	recent, err := client.GetLatestBlockhash(ctx, rpc.CommitmentConfirmed)
	if err != nil {
		panic(err)
	}
	tx, err := solana.NewTransaction(
		[]solana.Instruction{createInstruction},
		recent.Value.Blockhash,
		solana.TransactionPayer(payer.PublicKey()),
	)
	if err != nil {
		panic(err)
	}
	tx.Sign(func(key solana.PublicKey) *solana.PrivateKey {
		if key.Equals(mint.PublicKey()) {
			return &mint.PrivateKey
		}
		return &payer.PrivateKey
	})

	sig, err := client.SendTransactionWithOpts(ctx, tx, rpc.TransactionOpts{
		PreflightCommitment: rpc.CommitmentConfirmed,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("Transaction Signature:", sig)
	fmt.Println("Mint Address:", mint.PublicKey())
}
```

<div className="sol-run" data-run="cookbook/tokens/create-token-with-metadata/create" data-tab="Go">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Output from a local Surfpool network</span></div>
<div className="sol-run-out">

```text Output
Transaction Signature: 3W8cVcG29ncaWWMPzax9JdPTuFJYF5ebJcQmdswG8AQLYRRq1WahWK8ncgK23DTkxJBxA9TB6d2C7FzLmVFFosUM
Mint Address: AmQygVa7AiorQgaFZXnGxNmpVnb5rQSEzmaYbXC17y5s
```

</div>
</div>

</Tab>
</Tabs>
