> ## Documentation Index
> Fetch the complete documentation index at: https://luminouslabs-cc5545c6-indexing-tokens.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Token Pools for Compression to Existing Mints

> Create a token pool for an existing SPL mint. Requires only fee_payer with no mint authority constraint.

Create a token for compression fo an existing SPL mint. `createTokenPool()` requires only `fee_payer` and has no mint authority constraint.

<Info>
  The token pool account itself requires rent, but individual compressed token accounts are rent-free.
</Info>

<CodeGroup>
  ```typescript function-create-token-pool.ts theme={null}
  // Creates token pool account for existing SPL mint
  const transactionSignature = await createTokenPool(
      rpc,
      payer,
      mint,
  );
  ```
</CodeGroup>

<Check>
  **Best Practice:** Each mint supports a maximum of 4 token pools total. During compression/decompression operations, token pools get write-locked. Use `addTokenPools()` to create additional pools that increase per-block write-lock capacity.
</Check>

## Get Started

<Steps>
  <Step>
    ### Create Token Pool

    <Accordion title="Installation">
      <Tabs>
        <Tab title="npm">
          Install packages in your working directory:

          ```bash theme={null}
          npm install @lightprotocol/stateless.js@beta \
                      @lightprotocol/compressed-token@beta
          ```

          Install the CLI globally:

          ```bash theme={null}
          npm install -g @lightprotocol/zk-compression-cli@beta
          ```
        </Tab>

        <Tab title="yarn">
          Install packages in your working directory:

          ```bash theme={null}
          yarn add @lightprotocol/stateless.js@beta \
                   @lightprotocol/compressed-token@beta
          ```

          Install the CLI globally:

          ```bash theme={null}
          yarn global add @lightprotocol/zk-compression-cli@beta
          ```
        </Tab>

        <Tab title="pnpm">
          Install packages in your working directory:

          ```bash theme={null}
          pnpm add @lightprotocol/stateless.js@beta \
                   @lightprotocol/compressed-token@beta
          ```

          Install the CLI globally:

          ```bash theme={null}
          pnpm add -g @lightprotocol/zk-compression-cli@beta
          ```
        </Tab>
      </Tabs>
    </Accordion>

    <Tabs>
      <Tab title="Localnet">
        ```bash theme={null}
        # start local test-validator in a separate terminal
        light test-validator
        ```

        <Note>
          In the code examples, use `createRpc()` without arguments for localnet.
        </Note>
      </Tab>

      <Tab title="Devnet">
        Get an API key from [Helius](https://helius.dev) and add to `.env`:

        ```bash title=".env" theme={null}
        API_KEY=<your-helius-api-key>
        ```

        <Note>
          In the code examples, use `createRpc(RPC_URL)` with the devnet URL.
        </Note>
      </Tab>
    </Tabs>

    ```typescript theme={null}
    import "dotenv/config";
    import { Keypair, PublicKey } from "@solana/web3.js";
    import { createRpc } from "@lightprotocol/stateless.js";
    import { createTokenPool } from "@lightprotocol/compressed-token";
    import { createMint as createSplMint, TOKEN_PROGRAM_ID } from "@solana/spl-token";
    import { homedir } from "os";
    import { readFileSync } from "fs";

    // devnet:
    const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
    // localnet:
    // const RPC_URL = undefined;
    const payer = Keypair.fromSecretKey(
        new Uint8Array(
            JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
        )
    );

    (async function () {
        // devnet:
        const rpc = createRpc(RPC_URL);
        // localnet:
        // const rpc = createRpc();

        // Setup: Create existing SPL mint
        const mintKeypair = Keypair.generate();
        await createSplMint(rpc, payer, payer.publicKey, null, 9, mintKeypair, undefined, TOKEN_PROGRAM_ID);

        // Create token pool for existing mint
        const tx = await createTokenPool(rpc, payer, mintKeypair.publicKey);

        console.log("Mint:", mintKeypair.publicKey.toBase58());
        console.log("Tx:", tx);
    })();
    ```
  </Step>
</Steps>

# Troubleshooting

<AccordionGroup>
  <Accordion title="TokenPool not found">
    You're trying to access a token pool that doesn't exist.

    ```typescript theme={null}
    // Create the missing token pool
    const poolTx = await createTokenPool(rpc, payer, mint);
    console.log("Token pool created:", poolTx);
    ```
  </Accordion>
</AccordionGroup>

# Advanced Configuration

<AccordionGroup>
  <Accordion title="Batch Pool Creation">
    Create pools for multiple mints:

    ```typescript theme={null}
    const mints = [
        new PublicKey("MINT_1_ADDRESS"),
        new PublicKey("MINT_2_ADDRESS"),
        new PublicKey("MINT_3_ADDRESS"),
    ];

    for (const mint of mints) {
        try {
            const poolTx = await createTokenPool(rpc, payer, mint);
            console.log(`Pool created for ${mint.toBase58()}:`, poolTx);
        } catch (error) {
            console.log(`Failed for ${mint.toBase58()}:`, error.message);
        }
    }
    ```
  </Accordion>

  <Accordion title="Create Pool with Token-2022">
    Create token pools for Token-2022 mints:

    ```typescript theme={null}
    import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';

    const poolTx = await createTokenPool(
        rpc,
        payer,
        mint, // Token-2022 mint
        undefined,
        TOKEN_2022_PROGRAM_ID,
    );
    ```
  </Accordion>
</AccordionGroup>

# Next Steps

<Card title="How to Merge Compressed Token Accounts" icon="chevron-right" color="#0066ff" href="/compressed-tokens/guides/merge-compressed-token-accounts" horizontal />
