> ## Documentation Index
> Fetch the complete documentation index at: https://www.zkcompression.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Interface PDAs for Compression to Existing Mints

> Create an interface PDA for an existing SPL mint. Requires only fee_payer with no mint authority constraint.

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

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

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

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

## Get Started

<Steps>
  <Step>
    ### Create Interface PDA

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

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

          Install the CLI globally:

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

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

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

          Install the CLI globally:

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

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

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

          Install the CLI globally:

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

        <Tab title="SDK 2.0 (token-interface)">
          Install packages in your working directory:

          ```bash theme={null}
          # npm
          npm install @lightprotocol/stateless.js@^0.23.0 \
                      @lightprotocol/token-interface@^0.1.2

          # yarn
          yarn add @lightprotocol/stateless.js@^0.23.0 \
                   @lightprotocol/token-interface@^0.1.2

          # pnpm
          pnpm add @lightprotocol/stateless.js@^0.23.0 \
                   @lightprotocol/token-interface@^0.1.2
          ```

          Install the CLI globally:

          ```bash theme={null}
          npm install -g @lightprotocol/zk-compression-cli
          ```
        </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 interface PDA 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 an interface PDA that doesn't exist.

    ```typescript theme={null}
    // Create the missing interface PDA
    const poolTx = await createTokenPool(rpc, payer, mint);
    console.log("Interface PDA 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 interface PDAs 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 />
