# Creating a Token-2022 on Solana

This guide explains how to quickly mint a Token-2022 compliant SPL token on Solana Devnet using the command-line interface (CLI). It also shows how to enable and use token extensions such as metadata and transfer fees.

***

### Prerequisites

1. **Install Solana CLI**

   ```bash
   sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
   ```
2. **Install SPL Token CLI** (must support Token-2022)

   ```bash
   cargo install spl-token-cli
   ```
3. **Set Up Solana CLI for Devnet**

   ```bash
   solana config set --url https://api.devnet.solana.com
   solana config set --keypair /path/to/your/dev-wallet.json
   ```
4. **Airdrop Some SOL for Fees**

   ```bash
   solana airdrop 2
   ```

***

### Step-by-Step Token-2022 Minting

#### 1. Create a Token-2022 Mint

```bash
spl-token create-token \
  --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
```

Save the returned token mint address.

#### 2. Create a Token Account for Your Wallet

```bash
spl-token create-account <TOKEN_MINT_ADDRESS> \
  --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
```

#### 3. Mint Tokens to Your Account

```bash
spl-token mint <TOKEN_MINT_ADDRESS> 1000 \
  --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
```

#### 4. Confirm Token Balance

```bash
spl-token accounts --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
```

***

### Adding Token Extensions

Token-2022 supports advanced features called extensions. Below are examples of two useful ones.

#### Extension 1: Transfer Fee

This allows collecting fees on every token transfer.

**Create Mint with Transfer Fee Extension**

```bash
spl-token create-token \
  --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb \
  --enable-extensions transferFeeConfig
```

**Initialize Transfer Fee**

```bash
spl-token enable-transfer-fee \
  <TOKEN_MINT_ADDRESS> \
  --transfer-fee-config-authority <YOUR_WALLET_ADDRESS> \
  --transfer-fee-basis-points 25 \
  --maximum-transfer-fee 10
```

This sets a 0.25% fee (25 basis points) with a max of 10 tokens per transfer.

***

#### Extension 2: Metadata

This enables rich token metadata like name, symbol, and image.

**Initialize Metadata**

```bash
spl-token initialize-metadata <TOKEN_MINT_ADDRESS> \
  "My Test Token" "MTT" "https://example.com/token-metadata.json"
```

Make sure the JSON metadata file at that URL is hosted and follows the standard format.

***

### Resources

* Token-2022 Documentation: <https://spl.solana.com/token-2022>
* Solana Devnet Explorer: [https://explorer.solana.com?cluster=devnet](https://explorer.solana.com/?cluster=devnet)

***

### Notes

* You must use the `--program-id Tokenz...` flag for all Token-2022 interactions.
* Some extensions require initializing during the token mint creation.
* Not all wallets or exchanges currently support Token-2022 tokens.

***

Happy minting!
