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

# Create a Token Mint

> Learn how to create a token mint with Confidential Balances enabled.

## How to create a mint with Confidential Balances

Confidential Balances enables private token transfers by adding extra state to
the mint account. This section explains how to create a token mint with the
required extension enabled.

The following diagram shows the steps involved in creating a mint with the
Confidential Balances extension:

```mermaid
sequenceDiagram
    participant Payer as Wallet
    participant Token22 as Token Extensions Program
    participant Mint as Mint Account

    Payer->>Token22: create_mint <br>(with Confidential Balances)
    activate Token22
    Token22-->>Mint: Initialize mint with extension data
    deactivate Token22
```

<div className="sol-mermaid" data-fallback="mermaid" data-mermaid="1cd56a809675">
  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/1cd56a809675-light.svg" alt="Create Mint with Confidential Balances" />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/1cd56a809675.svg" alt="Create Mint with Confidential Balances" />

  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/1cd56a809675-sm-light.svg" alt="Create Mint with Confidential Balances" />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/1cd56a809675-sm.svg" alt="Create Mint with Confidential Balances" />
</div>

<p className="sol-caption">Create Mint with Confidential Balances</p>

### Confidential Balances Mint State

The extension adds the
[ConfidentialTransferMint](https://github.com/solana-program/token-2022/blob/efd0c957fefbd79882d77df5fb2dac88c001249c/program/src/extension/confidential_transfer/mod.rs#L48-L69)
state to the mint account:

```rust title="Confidential Mint State"
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct ConfidentialTransferMint {
    /// Authority to modify the `ConfidentialTransferMint` configuration and to
    /// approve new accounts (if `auto_approve_new_accounts` is true)
    ///
    /// The legacy Token Multisig account is not supported as the authority
    pub authority: OptionalNonZeroPubkey,

    /// Indicate if newly configured accounts must be approved by the
    /// `authority` before they may be used by the user.
    ///
    /// * If `true`, no approval is required and new accounts may be used
    ///   immediately
    /// * If `false`, the authority must approve newly configured accounts (see
    ///   `ConfidentialTransferInstruction::ConfigureAccount`)
    pub auto_approve_new_accounts: PodBool,

    /// Authority to decode any transfer amount in a confidential transfer.
    pub auditor_elgamal_pubkey: OptionalNonZeroElGamalPubkey,
}
```

The `ConfidentialTransferMint` contains three configuration fields:

- **authority**: The account that has permission to change Confidential Balances
  settings for the mint and approve new confidential accounts if auto-approval
  is disabled.

- **auto_approve_new_accounts**: When set to true, users can create token
  accounts with Confidential Balances enabled by default. When false, the
  authority must approve each new token account before it can be used for
  confidential transfers.

- **auditor_elgamal_pubkey**: An optional auditor that can decrypt transfer
  amounts in confidential transactions, providing a compliance mechanism while
  maintaining privacy from the general public.

### Required Instructions

Creating a mint with Confidential Balances enabled requires three instructions
in a single transaction:

1. **Create the Mint Account**: Invoke the System Program's `CreateAccount`
   instruction to create the mint account.

2. **Initialize Confidential Balances**: Invoke the Token Extension Program's
   [ConfidentialTransferInstruction::InitializeMint](https://github.com/solana-program/token-2022/blob/efd0c957fefbd79882d77df5fb2dac88c001249c/program/src/extension/confidential_transfer/processor.rs#L48)
   instruction to configure the `ConfidentialTransferMint` state for the
   mint.

3. **Initialize Mint**: Invoke the Token Extension Program's
   `Instruction::InitializeMint` instruction to initialize the standard mint
   state.

The `spl_token_client` crate's `create_mint` method can build and send all
three in one call. The examples below build the three instructions directly, so
you can see each one.

## Example Code

The following code demonstrates how to create a mint with Confidential Balances
enabled.

Confidential Balances depends on the ZK ElGamal Proof program, which is enabled
on mainnet and devnet. The Token-2022 program bundled with
`solana-test-validator` is built without confidential-transfer support, so
Deposit and the steps after it fail with `InvalidInstructionData`. Run the
examples on devnet (the code's default; get devnet SOL from the
[Solana faucet](https://faucet.solana.com)) or on a mainnet-forking local
validator such as [Surfpool](https://surfpool.run). The payer is the wallet at
`~/.config/solana/id.json`, and the example creates its own mint, so there are
no addresses to replace.

The mint's auditor key comes from a second wallet. Create it before you run the
example:

```bash Terminal
solana-keygen new -o ~/.config/solana/auditor.json
```

### Rust

<CodeGroup>

```rust main.rs expandable
// Imports: dependencies used by this example.
use anyhow::{Context, Result};
use solana_client::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_keypair::Keypair;
use solana_signer::Signer;
use solana_system_interface::instruction as system_instruction;
use solana_transaction::Transaction;
use solana_zk_sdk::encryption::derivation::derive_confidential_keys;
use solana_zk_sdk_pod::encryption::elgamal::PodElGamalPubkey;
use spl_token_2022::{
    extension::{
        confidential_transfer::instruction::initialize_mint as initialize_confidential_transfer_mint,
        ExtensionType,
    },
    instruction::initialize_mint as initialize_mint_base,
    state::Mint,
};

fn main() -> Result<()> {
    let rpc_client = RpcClient::new_with_commitment(
        String::from("https://api.devnet.solana.com"),
        CommitmentConfig::confirmed(),
    );

    let payer = load_keypair(".config/solana/id.json")?;
    let mint = Keypair::new();
    let decimals: u8 = 2;

    // Allocate space for a mint that carries the ConfidentialTransferMint
    // extension, then fund it for rent exemption.
    let space =
        ExtensionType::try_calculate_account_len::<Mint>(&[ExtensionType::ConfidentialTransferMint])?;
    let rent = rpc_client.get_minimum_balance_for_rent_exemption(space)?;

    // The auditor ElGamal key lets the issuer decrypt transfer amounts for
    // compliance. Pass `None` to create a mint with no auditor. Derive it from
    // the auditor's own wallet (`solana-keygen new -o
    // ~/.config/solana/auditor.json`); in production the auditor sends the
    // public key alone.
    let auditor_wallet = load_keypair(".config/solana/auditor.json")?;
    let (auditor, _auditor_aes_key) = derive_confidential_keys(&auditor_wallet, &[])
        .map_err(|e| anyhow::anyhow!("derive auditor keys: {e}"))?;
    let auditor_pubkey: PodElGamalPubkey = (*auditor.pubkey()).into();

    let create_account_ix = system_instruction::create_account(
        &payer.pubkey(),
        &mint.pubkey(),
        rent,
        space as u64,
        &spl_token_2022::id(),
    );

    // The confidential-transfer extension must be initialized before the base
    // mint and cannot be added later.
    let init_confidential_ix = initialize_confidential_transfer_mint(
        &spl_token_2022::id(),
        &mint.pubkey(),
        Some(payer.pubkey()), // authority that can update confidential settings
        true,                 // auto-approve new accounts
        Some(auditor_pubkey),
    )?;

    let init_mint_ix = initialize_mint_base(
        &spl_token_2022::id(),
        &mint.pubkey(),
        &payer.pubkey(), // mint authority
        None,            // freeze authority
        decimals,
    )?;

    let blockhash = rpc_client.get_latest_blockhash()?;
    let transaction = Transaction::new_signed_with_payer(
        &[create_account_ix, init_confidential_ix, init_mint_ix],
        Some(&payer.pubkey()),
        &[&payer, &mint],
        blockhash,
    );
    let signature = rpc_client.send_and_confirm_transaction(&transaction)?;
    println!("Created confidential mint {}: {signature}", mint.pubkey());
    Ok(())
}

fn load_keypair(relative_path: &str) -> Result<Keypair> {
    let keypair_path = dirs::home_dir()
        .context("could not find home directory")?
        .join(relative_path);
    let bytes: Vec<u8> = serde_json::from_reader(std::fs::File::open(keypair_path)?)?;
    let mut secret = [0u8; 32];
    secret.copy_from_slice(&bytes[0..32]);
    Ok(Keypair::new_from_array(secret))
}
```

```toml Cargo.toml
[package]
name = "confidential-mint"
version = "0.1.0"
edition = "2021"

# spl-token-2022 11 requires solana-system-interface 3.2 (which needs
# solana-instruction >= 3.4), so this example uses the granular solana-* crates
# instead of the solana-sdk umbrella. Keep solana-client on the 4.3 line (rustc
# 1.97.1 or later): 4.4 moved to solana-transaction 5, so it no longer matches
# the solana-transaction 4 that this example builds transactions with.
[dependencies]
solana-client = "~4.3"
solana-pubkey = "4.2"
solana-keypair = "3.1"
solana-signer = "3.0"
solana-transaction = "4"
solana-commitment-config = "3.1.1"
solana-system-interface = { version = "3.2.0", features = ["bincode"] }
solana-zk-sdk = "7.0.1"
solana-zk-sdk-pod = "0.1.2"
spl-token-2022 = { version = "11.0.0", features = ["zk-ops"] }

anyhow = "1.0"
dirs = "6.0.0"
serde_json = "1.0"
```

</CodeGroup>

### Typescript

<CodeGroup>

```ts index.ts expandable
// Imports: dependencies used by this example.
import { getCreateMintInstructionPlan } from "@solana-program/token-2022";
import { deriveConfidentialKeys } from "@solana-program/token-2022/confidential";
import {
  createClient,
  createKeyPairSignerFromBytes,
  generateKeyPairSigner,
  some
} from "@solana/kit";
import { solanaRpc } from "@solana/kit-plugin-rpc";
import { signerFromFile } from "@solana/kit-plugin-signer";
import { readFile } from "node:fs/promises";
import { homedir } from "node:os";
import { join } from "node:path";

const client = await createClient()
  .use(signerFromFile(join(homedir(), ".config/solana/id.json")))
  .use(
    solanaRpc({
      rpcUrl: "https://api.devnet.solana.com"
    })
  );
const payer = client.payer;

const mint = await generateKeyPairSigner();

// The auditor ElGamal key lets the issuer decrypt transfer amounts for
// compliance. Omit `auditorElgamalPubkey` to create a mint with no auditor.
// Derive it from the auditor's own wallet (`solana-keygen new -o
// ~/.config/solana/auditor.json`); in production the auditor sends the
// public key alone.
const auditorSigner = await createKeyPairSignerFromBytes(
  new Uint8Array(
    JSON.parse(
      await readFile(join(homedir(), ".config/solana/auditor.json"), "utf8")
    )
  )
);
const { elgamalKeypair: auditor } = await deriveConfidentialKeys({
  signer: auditorSigner
});

const plan = await getCreateMintInstructionPlan(client, {
  payer,
  newMint: mint,
  decimals: 2,
  mintAuthority: payer,
  extensions: [
    {
      __kind: "ConfidentialTransferMint",
      authority: some(payer.address),
      autoApproveNewAccounts: true,
      auditorElgamalPubkey: some(auditor.elgamalPubkey)
    }
  ]
});

const result = await client.sendTransaction(plan);

console.log(
  `Created confidential mint ${mint.address}: ${result.context.signature}`
);
```

```json package.json
{
  "name": "confidential-mint",
  "version": "0.1.0",
  "type": "module",
  "dependencies": {
    "@solana-program/system": "^0.15.0",
    "@solana-program/token-2022": "^0.19.0",
    "@solana/kit": "^8.4.0",
    "@solana/kit-plugin-rpc": "^0.19.0",
    "@solana/kit-plugin-signer": "^0.19.0",
    "@solana/zk-sdk": "^0.5.1"
  },
  "devDependencies": {
    "@types/node": "^24.10.0",
    "typescript": "^5.8.3"
  }
}
```

</CodeGroup>
