> ## 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-2022 Mint with Extensions

> Create a compliance-ready Token-2022 mint with onchain metadata, pausable transfers, a permanent delegate, and frozen-by-default accounts, in Kit, web3.js v3, Rust, or legacy web3.js.

This example creates a Token-2022 mint with onchain metadata, pausable
transfers, a permanent delegate, and token accounts that start frozen. It is the
same set of extensions the [Issue an asset](/developers/docs/assets/issue-asset) path
uses, written in Kit, web3.js v3, Rust, and legacy web3.js. Pick a tab, then
run it on the isolated test network:

<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 { getCreateAccountInstruction } from "@solana-program/system";
import {
  AccountState,
  TOKEN_2022_PROGRAM_ADDRESS,
  extension,
  fetchMint,
  getInitializeMintInstruction,
  getMintSize,
  getPostInitializeInstructionsForMintExtensions,
  getPreInitializeInstructionsForMintExtensions,
} from "@solana-program/token-2022";

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

// A compliance-ready Token-2022 mint: onchain metadata, pausable transfers,
// a permanent delegate that can move or burn any balance, and token accounts
// that start frozen until the issuer thaws them.
const extensions = [
  extension("MetadataPointer", {
    authority: payer.address,
    metadataAddress: mint.address,
  }),
  extension("TokenMetadata", {
    updateAuthority: payer.address,
    mint: mint.address,
    name: "Example Stablecoin",
    symbol: "EXUSD",
    uri: "https://example.com/exusd.json",
    additionalMetadata: new Map<string, string>(),
  }),
  extension("PausableConfig", { authority: payer.address, paused: false }),
  extension("PermanentDelegate", { delegate: payer.address }),
  extension("DefaultAccountState", { state: AccountState.Frozen }),
];

// Token metadata is written after the mint is initialized, so allocate the
// account without it but fund rent for the full size.
const spaceWithoutMetadata = BigInt(
  getMintSize(extensions.filter(({ __kind }) => __kind !== "TokenMetadata")),
);
const spaceWithMetadata = BigInt(getMintSize(extensions));
const rent = await client.rpc
  .getMinimumBalanceForRentExemption(spaceWithMetadata)
  .send();

const instructions = [
  getCreateAccountInstruction({
    payer,
    newAccount: mint,
    lamports: rent,
    space: spaceWithoutMetadata,
    programAddress: TOKEN_2022_PROGRAM_ADDRESS,
  }),
  ...getPreInitializeInstructionsForMintExtensions(mint.address, extensions),
  getInitializeMintInstruction({
    mint: mint.address,
    decimals: 6,
    mintAuthority: payer.address,
    freezeAuthority: payer.address,
  }),
  ...getPostInitializeInstructionsForMintExtensions(
    mint.address,
    payer,
    extensions,
  ),
];

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

// Verify the mint and its extensions
const mintAccount = await fetchMint(client.rpc, mint.address);
const enabledExtensions =
  mintAccount.data.extensions.__option === "Some"
    ? mintAccount.data.extensions.value.map(({ __kind }) => __kind)
    : [];

console.log("Mint Address:", mintAccount.address);
console.log("Decimals:", mintAccount.data.decimals);
console.log("Extensions:", enabledExtensions.join(", "));
```

<div className="sol-run" data-run="cookbook/tokens/create-mint-with-extensions/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: kRvkXz1oN45UpGAzCQyPej9waAYRbtX2pw7aVnmHMwc95nmBcJFT5SoDZG7Qw4aknxabJqHDtbkY3B8ERoiYbW4
Mint Address: 6iKdvfEkw3JUnbdTbdj6aw1R4ebVzQTGXh3NGzWYJpxK
Decimals: 6
Extensions: MetadataPointer, PausableConfig, PermanentDelegate, DefaultAccountState, TokenMetadata
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
import {
  Connection,
  Keypair,
  LAMPORTS_PER_SOL,
  Transaction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";
import {
  AccountState,
  extension,
  getCreateMintInstructionPlan,
  getMintDecoder,
} from "@solana-program/token-2022";

const payer = await Keypair.generate();
const mint = await Keypair.generate();

const connection = new Connection("http://localhost:8899", "confirmed");

const airdropSignature = await connection.requestAirdrop(
  payer.publicKey,
  LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);

// A compliance-ready Token-2022 mint: onchain metadata, pausable transfers,
// a permanent delegate that can move or burn any balance, and token accounts
// that start frozen until the issuer thaws them.
const extensions = [
  extension("MetadataPointer", {
    authority: payer.publicKey.toBase58(),
    metadataAddress: mint.publicKey.toBase58(),
  }),
  extension("TokenMetadata", {
    updateAuthority: payer.publicKey.toBase58(),
    mint: mint.publicKey.toBase58(),
    name: "Example Stablecoin",
    symbol: "EXUSD",
    uri: "https://example.com/exusd.json",
    additionalMetadata: new Map<string, string>(),
  }),
  extension("PausableConfig", {
    authority: payer.publicKey.toBase58(),
    paused: false,
  }),
  extension("PermanentDelegate", { delegate: payer.publicKey.toBase58() }),
  extension("DefaultAccountState", { state: AccountState.Frozen }),
];

const transaction = new Transaction().add(
  await getCreateMintInstructionPlan(
    {
      getMinimumBalance: (space: number) =>
        connection.getMinimumBalanceForRentExemption(space),
    },
    {
      payer,
      newMint: mint,
      decimals: 6,
      mintAuthority: payer,
      freezeAuthority: payer.publicKey.toBase58(),
      extensions,
    },
  ),
);

const signature = await sendAndConfirmTransaction(connection, transaction, [
  payer,
  mint,
]);
console.log("Transaction Signature:", signature);

// Verify the mint and its extensions
const mintAccountInfo = await connection.getAccountInfo(mint.publicKey);
const mintAccount = getMintDecoder().decode(mintAccountInfo!.data);
const enabledExtensions =
  mintAccount.extensions.__option === "Some"
    ? mintAccount.extensions.value.map(({ __kind }) => __kind)
    : [];

console.log("Mint Address:", mint.publicKey.toBase58());
console.log("Decimals:", mintAccount.decimals);
console.log("Extensions:", enabledExtensions.join(", "));
```

<div className="sol-run" data-run="cookbook/tokens/create-mint-with-extensions/create" data-tab="Web3.js v3">
<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: 4xAC92gKQerBrNBRzPiC7pMsg5zx24XvifwxzxYdNA71PhmC38upPsZ4fTZmUsaMd1uZEBiJgVtAySuN4cetxD1j
Mint Address: 5dEEFEYcyx5aSAimoE9GCc8Dhfq8MJ279YMpLoMkcP6M
Decimals: 6
Extensions: MetadataPointer, PausableConfig, PermanentDelegate, DefaultAccountState, TokenMetadata
```

</div>
</div>

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

```rust
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_sdk::{
    native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction,
};
use solana_system_interface::instruction::create_account;
use spl_token_2022_interface::{
    extension::{
        default_account_state::instruction::initialize_default_account_state, metadata_pointer,
        pausable, BaseStateWithExtensions, ExtensionType, StateWithExtensions,
    },
    instruction::{initialize_mint2, initialize_permanent_delegate},
    state::{AccountState, Mint},
};
use spl_token_metadata_interface::state::TokenMetadata;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("http://localhost:8899"),
        CommitmentConfig::confirmed(),
    );

    let payer = Keypair::new();
    let mint = Keypair::new();
    let token_program = spl_token_2022_interface::id();

    let airdrop_signature = client
        .request_airdrop(&payer.pubkey(), LAMPORTS_PER_SOL)
        .await?;
    loop {
        if client.confirm_transaction(&airdrop_signature).await? {
            break;
        }
    }

    // A compliance-ready Token-2022 mint: onchain metadata, pausable
    // transfers, a permanent delegate that can move or burn any balance, and
    // token accounts that start frozen until the issuer thaws them.
    let metadata = TokenMetadata {
        update_authority: Some(payer.pubkey()).try_into()?,
        mint: mint.pubkey(),
        name: String::from("Example Stablecoin"),
        symbol: String::from("EXUSD"),
        uri: String::from("https://example.com/exusd.json"),
        additional_metadata: vec![],
    };

    // Token metadata is written after the mint is initialized, so allocate
    // the account without it but fund rent for the full size.
    let mint_len = ExtensionType::try_calculate_account_len::<Mint>(&[
        ExtensionType::MetadataPointer,
        ExtensionType::Pausable,
        ExtensionType::PermanentDelegate,
        ExtensionType::DefaultAccountState,
    ])?;
    let metadata_len = metadata.tlv_size_of()?;
    let rent = client
        .get_minimum_balance_for_rent_exemption(mint_len + metadata_len)
        .await?;

    let instructions = vec![
        create_account(
            &payer.pubkey(),
            &mint.pubkey(),
            rent,
            mint_len as u64,
            &token_program,
        ),
        metadata_pointer::instruction::initialize(
            &token_program,
            &mint.pubkey(),
            Some(payer.pubkey()),
            Some(mint.pubkey()),
        )?,
        pausable::instruction::initialize(&token_program, &mint.pubkey(), &payer.pubkey())?,
        initialize_permanent_delegate(&token_program, &mint.pubkey(), &payer.pubkey())?,
        initialize_default_account_state(&token_program, &mint.pubkey(), &AccountState::Frozen)?,
        initialize_mint2(
            &token_program,
            &mint.pubkey(),
            &payer.pubkey(),
            Some(&payer.pubkey()),
            6,
        )?,
        spl_token_metadata_interface::instruction::initialize(
            &token_program,
            &mint.pubkey(),
            &payer.pubkey(),
            &mint.pubkey(),
            &payer.pubkey(),
            metadata.name.clone(),
            metadata.symbol.clone(),
            metadata.uri.clone(),
        ),
    ];

    let recent_blockhash = client.get_latest_blockhash().await?;
    let transaction = Transaction::new_signed_with_payer(
        &instructions,
        Some(&payer.pubkey()),
        &[&payer, &mint],
        recent_blockhash,
    );
    let signature = client.send_and_confirm_transaction(&transaction).await?;
    println!("Transaction Signature: {signature}");

    // Verify the mint and its extensions
    let mint_data = client.get_account_data(&mint.pubkey()).await?;
    let mint_state = StateWithExtensions::<Mint>::unpack(&mint_data)?;
    println!("Mint Address: {}", mint.pubkey());
    println!("Decimals: {}", mint_state.base.decimals);
    println!("Extensions: {:?}", mint_state.get_extension_types()?);

    Ok(())
}
```

<div className="sol-run" data-run="cookbook/tokens/create-mint-with-extensions/create" data-tab="Rust">
<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: 3Jf5kyRtRJiCXwdetNwfFMZHVEKzQmGimS9yGQtv1aRdZ2NQYuvgGhPjiQVC7Cd6XKB23NBsbCTWy6BhHz1XPTHr
Mint Address: 59Ni2UGQdrUy2Y8vBuChncUS1epmc2UmWXe1NbUGW4e7
Decimals: 6
Extensions: [MetadataPointer, Pausable, PermanentDelegate, DefaultAccountState, TokenMetadata]
```

</div>
</div>

</Tab>
<Tab title="Web3.js (legacy)">
<div className="sol-tab-label">Web3.js (legacy)</div>

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) 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.
</Warning>

```ts
import {
  Connection,
  Keypair,
  LAMPORTS_PER_SOL,
  SystemProgram,
  Transaction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";
import {
  AccountState,
  ExtensionType,
  LENGTH_SIZE,
  TOKEN_2022_PROGRAM_ID,
  TYPE_SIZE,
  createInitializeDefaultAccountStateInstruction,
  createInitializeMetadataPointerInstruction,
  createInitializeMintInstruction,
  createInitializePausableConfigInstruction,
  createInitializePermanentDelegateInstruction,
  getMintLen,
} from "@solana/spl-token";
import {
  createInitializeInstruction,
  pack,
  type TokenMetadata,
} from "@solana/spl-token-metadata";

const payer = Keypair.generate();
const mint = Keypair.generate();

const connection = new Connection("http://localhost:8899", "confirmed");

const airdropSignature = await connection.requestAirdrop(
  payer.publicKey,
  LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);

// A compliance-ready Token-2022 mint: onchain metadata, pausable transfers,
// a permanent delegate that can move or burn any balance, and token accounts
// that start frozen until the issuer thaws them.
const metadata: TokenMetadata = {
  updateAuthority: payer.publicKey,
  mint: mint.publicKey,
  name: "Example Stablecoin",
  symbol: "EXUSD",
  uri: "https://example.com/exusd.json",
  additionalMetadata: [],
};

// Token metadata is written after the mint is initialized, so allocate the
// account without it but fund rent for the full size.
const mintLen = getMintLen([
  ExtensionType.MetadataPointer,
  ExtensionType.PausableConfig,
  ExtensionType.PermanentDelegate,
  ExtensionType.DefaultAccountState,
]);
const metadataLen = TYPE_SIZE + LENGTH_SIZE + pack(metadata).length;
const rent = await connection.getMinimumBalanceForRentExemption(
  mintLen + metadataLen,
);

const transaction = new Transaction().add(
  SystemProgram.createAccount({
    fromPubkey: payer.publicKey,
    newAccountPubkey: mint.publicKey,
    space: mintLen,
    lamports: rent,
    programId: TOKEN_2022_PROGRAM_ID,
  }),
  createInitializeMetadataPointerInstruction(
    mint.publicKey,
    payer.publicKey,
    mint.publicKey,
    TOKEN_2022_PROGRAM_ID,
  ),
  createInitializePausableConfigInstruction(
    mint.publicKey,
    payer.publicKey,
    TOKEN_2022_PROGRAM_ID,
  ),
  createInitializePermanentDelegateInstruction(
    mint.publicKey,
    payer.publicKey,
    TOKEN_2022_PROGRAM_ID,
  ),
  createInitializeDefaultAccountStateInstruction(
    mint.publicKey,
    AccountState.Frozen,
    TOKEN_2022_PROGRAM_ID,
  ),
  createInitializeMintInstruction(
    mint.publicKey,
    6,
    payer.publicKey,
    payer.publicKey,
    TOKEN_2022_PROGRAM_ID,
  ),
  createInitializeInstruction({
    programId: TOKEN_2022_PROGRAM_ID,
    metadata: mint.publicKey,
    updateAuthority: payer.publicKey,
    mint: mint.publicKey,
    mintAuthority: payer.publicKey,
    name: metadata.name,
    symbol: metadata.symbol,
    uri: metadata.uri,
  }),
);

const signature = await sendAndConfirmTransaction(connection, transaction, [
  payer,
  mint,
]);
console.log("Transaction Signature:", signature);
console.log("Mint Address:", mint.publicKey.toBase58());
```

<div className="sol-run" data-run="cookbook/tokens/create-mint-with-extensions/create" data-tab="Web3.js (legacy)">
<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: 3UmdxJA66y2AwVYa7vLPiq5ebGteAaShE3qJ5KjXppvfdFFzNvFHSfuDBWGfBVRquS3LJiXe3AfizjkwwrcAWVSx
Mint Address: CDuhAWbSCG6Gx5FZPDkFL9rP3DqLb6S15rb9SwZSN945
```

</div>
</div>

</Tab>
</Tabs>

You should see the transaction signature and the mint address. The Kit, web3.js
v3, and Rust tabs also print the list of enabled extensions.

## Point it at devnet

Each tab generates a new payer and funds it with an airdrop, which only works on
a local network: the public devnet endpoint no longer serves airdrops. On
devnet, pay with a keypair you funded yourself. Get devnet SOL for your Solana
CLI keypair (`solana address` prints its address) from the
[Solana Faucet](https://faucet.solana.com) or another
[faucet](/developers/cookbook/development/airdrops-and-faucets), then, in your
tab, replace the lines that create the payer, the mint keypair and the RPC
connection, and the airdrop that follows them, with:

<CodeGroup>

```ts Kit
// These imports replace the tab's @solana/kit and Kit plugin imports
import { readFileSync } from "node:fs";
import { homedir } from "node:os";
import {
  createClient,
  createKeyPairSignerFromBytes,
  generateKeyPairSigner,
} from "@solana/kit";
import { solanaRpc } from "@solana/kit-plugin-rpc";
import { payer as kitPayer } from "@solana/kit-plugin-signer";

// A keypair you funded with devnet SOL from https://faucet.solana.com
const payer = await createKeyPairSignerFromBytes(
  new Uint8Array(
    JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")),
  ),
);
const mint = await generateKeyPairSigner();

// No rpcAirdrop() or airdropPayer(): the payer is already funded
const client = await createClient()
  .use(kitPayer(payer))
  .use(
    solanaRpc({
      rpcUrl: "https://api.devnet.solana.com",
      rpcSubscriptionsUrl: "wss://api.devnet.solana.com",
    }),
  );
```

```ts title="Web3.js v3"
import { readFileSync } from "node:fs";
import { homedir } from "node:os";

// A keypair you funded with devnet SOL from https://faucet.solana.com
const payer = await Keypair.fromSecretKey(
  Uint8Array.from(
    JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")),
  ),
);
const mint = await Keypair.generate();

// No requestAirdrop(): the payer is already funded
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
```

```rust Rust
// Import read_keypair_file (LAMPORTS_PER_SOL is no longer needed)
use solana_sdk::{
    signature::{read_keypair_file, Keypair},
    signer::Signer,
    transaction::Transaction,
};

// In main():
let client = RpcClient::new_with_commitment(
    String::from("https://api.devnet.solana.com"),
    CommitmentConfig::confirmed(),
);

// A keypair you funded with devnet SOL from https://faucet.solana.com
let payer = read_keypair_file(format!("{}/.config/solana/id.json", std::env::var("HOME")?))
    .map_err(|e| anyhow::anyhow!("failed to read keypair: {e}"))?;
let mint = Keypair::new();
let token_program = spl_token_2022_interface::id();

// No request_airdrop(): the payer is already funded
```

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) 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.
</Warning>

```ts title="Web3.js (legacy)"
import { readFileSync } from "node:fs";
import { homedir } from "node:os";

// A keypair you funded with devnet SOL from https://faucet.solana.com
const payer = Keypair.fromSecretKey(
  Uint8Array.from(
    JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")),
  ),
);
const mint = Keypair.generate();

// No requestAirdrop(): the payer is already funded
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
```

</CodeGroup>

Everything after the setup is unchanged. Before using the same configuration on
mainnet, plan authority management, compliance operations, and monitoring for
the asset: the [go-live checklist](/developers/docs/assets/issue-asset/go-live)
of the Issue an asset tutorial covers them.

## Where to go next

- [Issue an asset](/developers/docs/assets/issue-asset) - approve holders, block a
  transfer, pause, and claw back, step by step
- [Tokens on Solana](/developers/docs/tokens) - mint accounts, token accounts, and
  authorities
- [Token extensions](/developers/docs/tokens/extensions) - choose only the controls your
  asset needs
- [Token ACL](/developers/docs/tokenization/token-acl) - enforce allowlists and blocklists
- [Issue a gated token](/developers/docs/tokenization/tutorials/issuing) - the same
  mint with an onchain allowlist, permissioned burn, and its authorities on
  separate keys
- [Delivery versus payment](/developers/docs/tokenization/dvp) - settle an asset and its
  payment atomically
