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

# Overview & Program Template

> Compressed PDAs provide full composability and functionality of accounts at PDAs, without rent-exemption cost per account. Suited for accounts where each user or entity gets their own PDA and state is infrequently accessed.

| Creation Cost        |  Regular PDA | Compressed PDA |
| :------------------- | -----------: | -------------: |
| **100-byte account** | \~0.0016 SOL |   0.000015 SOL |

Compressed PDAs are derived using a specific program address and seed, like regular PDAs.
Custom programs invoke the <Tooltip tip="The program enforces compressed account layout with ownership and sum checks. It is invoked to create and interact with compressed accounts and tokens.">Light System program</Tooltip>
to create and update compressed accounts, instead of the System program.
Compressed PDAs are compressed accounts with an address.

<Info>
  Compressed PDAs are suited for:

  * Per-user state (profiles, preferences, credentials)
  * DePIN node accounts and stake accounts
  * Nullifiers to prevent an on-chain instruction from
    being executed twice (little implementation overhead and useful e.g. for [payments](/pda/compressed-pdas/nullifier-pda) or [ZK programs](zk/overview))
  * App state that is written to and read from infrequently

  For DeFi pools, vaults, shared state, pool accounts, or config accounts, use [Light-PDA](/pda/light-pda/overview) with minimal code changes.
</Info>

<Tabs>
  <Tab title="Create">
    <div className="hidden dark:block">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/71xq4qzgNsL3Pf0n/images/Untitled.png?fit=max&auto=format&n=71xq4qzgNsL3Pf0n&q=85&s=2c554d55dde35800d0a90f31325cd279" alt="" width="1146" height="639" data-path="images/Untitled.png" />
      </Frame>
    </div>

    <div className="block dark:hidden">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/image-22.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=df850eaa6399cddcbda614af57101f76" alt="" width="1146" height="639" data-path="images/image-22.png" />
      </Frame>
    </div>
  </Tab>

  <Tab title="Update">
    <div className="hidden dark:block">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/71xq4qzgNsL3Pf0n/images/Untitled-1.png?fit=max&auto=format&n=71xq4qzgNsL3Pf0n&q=85&s=2fe75a5b1f1f29e53624a907c0a812d9" alt="" width="1066" height="559" data-path="images/Untitled-1.png" />
      </Frame>
    </div>

    <div className="block dark:hidden">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/image-20.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=59403c64337aaaabd78fca5d427e155f" alt="" width="1146" height="639" data-path="images/image-20.png" />
      </Frame>
    </div>
  </Tab>

  <Tab title="Close">
    <div className="hidden dark:block">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/71xq4qzgNsL3Pf0n/images/Untitled-4.png?fit=max&auto=format&n=71xq4qzgNsL3Pf0n&q=85&s=1f0957ad41395269a85b9ee0a0786ae8" alt="" width="1146" height="639" data-path="images/Untitled-4.png" />
      </Frame>
    </div>

    <div className="block dark:hidden">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/image-23.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=a57ed977e7ccf26d18cba4c1fef15d5b" alt="" width="1146" height="639" data-path="images/image-23.png" />
      </Frame>
    </div>
  </Tab>

  <Tab title="Reinitialize">
    <div className="hidden dark:block">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/program-reinit-1.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=69daca8882ac0f4af300480082e1e991" alt="" width="1146" height="639" data-path="images/program-reinit-1.png" />
      </Frame>
    </div>

    <div className="block dark:hidden">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/program-reinit.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=1ee6178a3f20459360eeaacea7655f5e" alt="" width="1146" height="639" data-path="images/program-reinit.png" />
      </Frame>
    </div>
  </Tab>

  <Tab title="Burn">
    <div className="hidden dark:block">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/program-burn-1.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=85aa9d485b05219be69cb366f01beafa" alt="" width="1146" height="639" data-path="images/program-burn-1.png" />
      </Frame>
    </div>

    <div className="block dark:hidden">
      <Frame>
        <img src="https://mintcdn.com/luminouslabs-cc5545c6/_CD81U5EBeZEhMtt/images/program-burn.png?fit=max&auto=format&n=_CD81U5EBeZEhMtt&q=85&s=9c7b0bbfe1dedddb5df78e0ff8ec61e9" alt="" width="1146" height="639" data-path="images/program-burn.png" />
      </Frame>
    </div>
  </Tab>
</Tabs>

# Start Building with the Program Template

<Steps>
  <Step>
    ### Prerequisites

    <Info>
      Required versions:

      * **Rust**: 1.90.0 or later
      * **Solana CLI**: 2.3.11 or later
      * **Anchor CLI**: 0.31.1
      * **Zk compression CLI**: 0.27.0 or later
      * **Node.js**: 22 or later
    </Info>

    **Install Solana CLI:**

    ```bash theme={null}
    sh -c "$(curl -sSfL https://release.solana.com/v2.2.15/install)"
    ```

    **Install Anchor CLI:**

    ```bash theme={null}
    cargo install --git https://github.com/coral-xyz/anchor avm --force
    avm install latest
    avm use latest
    ```

    **Install the Light CLI:**

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

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

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

    **Verify installation:**

    ```bash theme={null}
    light --version
    ```
  </Step>

  <Step>
    ### Initialize your Program

    Instantiate a template Solana program with compressed accounts with all required dependencies.

    ```bash theme={null}
    light init testprogram
    ```

    <Info>
      The `light init` command creates only Anchor-based projects . For Pinocchio programs, manually configure dependencies using `light-sdk-pinocchio`.
    </Info>

    <Accordion title="Dependencies">
      **Rust Crates**

      * `light-sdk` - Core SDK for compressed accounts in native and anchor programs
      * `light-sdk-pinocchio` Core SDK for compressed accounts in pinocchio programs
      * `light-client` - RPC client and indexer for interacting with compressed accounts
      * `light-program-test` - Testing utilities for compressed programs.

      **TypeScript/JavaScript Packages**

      * `@lightprotocol/stateless.js` - Client library for interacting with compressed accounts
      * `@lightprotocol/zk-compression-cli` - Command-line tools for ZK compression development
    </Accordion>
  </Step>

  <Step>
    ### Build and Test

    Now `cd testprogram` and run:

    ```bash theme={null}
    anchor build
    # Success: Finished `release` profile [optimized] target(s), after compiling.
    # Note: Stack offset warnings are expected and don't prevent compilation
    ```

    ```bash theme={null}
    cargo test-sbf

    # Success: test result: ok. 1 passed; 0 failed; 0 ignored
    ```
  </Step>
</Steps>

## Common Errors

<Accordion title="assert.h file not found - during compilation.">
  ```shellscript theme={null}
  Fix:
  In your terminal, run:
  1. export CC=$(xcrun -find clang)
  2. export SDKROOT=$(xcrun --show-sdk-path)
  3. cargo clean
  4. anchor build


  Example log:
  The following warnings were emitted during compilation:

  warning: blake3@1.5.1: In file included from c/blake3_neon.c:1:
  warning: blake3@1.5.1: c/blake3_impl.h:4:10: fatal error: 'assert.h' file not found
  warning: blake3@1.5.1:     4 | #include <assert.h>
  warning: blake3@1.5.1:       |          ^~~~~~~~~~
  warning: blake3@1.5.1: 1 error generated.

  error: failed to run custom build command for `blake3 v1.5.1`

  Caused by:
    process didn't exit successfully: `/Users/you/testprogram/target/release/build/blake3-ac41d29c2eabe052/build-script-build` (exit status: 1)
    --- stdout
    cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
    cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
    cargo:rerun-if-env-changed=CARGO_FEATURE_NEON
    cargo:rerun-if-env-changed=CARGO_FEATURE_NEON
    cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
    cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
    cargo:rustc-cfg=blake3_neon
    OUT_DIR = Some(/Users/you/testprogram/target/release/build/blake3-735a4c71d985df30/out)
    TARGET = Some(aarch64-apple-darwin)
    OPT_LEVEL = Some(3)
    HOST = Some(aarch64-apple-darwin)
    cargo:rerun-if-env-changed=CC_aarch64-apple-darwin
    CC_aarch64-apple-darwin = None
    cargo:rerun-if-env-changed=CC_aarch64_apple_darwin
    CC_aarch64_apple_darwin = None
    cargo:rerun-if-env-changed=HOST_CC
    HOST_CC = None
    cargo:rerun-if-env-changed=CC
    CC = Some(/Users/you/.local/share/solana/install/releases/1.18.22/solana-release/bin/sdk/sbf/dependencies/platform-tools/llvm/bin/clang)
    RUSTC_WRAPPER = None
    cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
    cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
    CRATE_CC_NO_DEFAULTS = None
    DEBUG = Some(false)
    cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET
    MACOSX_DEPLOYMENT_TARGET = None
    cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin
    CFLAGS_aarch64-apple-darwin = None
    cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin
    CFLAGS_aarch64_apple_darwin = None
    cargo:rerun-if-env-changed=HOST_CFLAGS
    HOST_CFLAGS = None
    cargo:rerun-if-env-changed=CFLAGS
    CFLAGS = None
    cargo:warning=In file included from c/blake3_neon.c:1:
    cargo:warning=c/blake3_impl.h:4:10: fatal error: 'assert.h' file not found
    cargo:warning=    4 | #include <assert.h>
    cargo:warning=      |          ^~~~~~~~~~
    cargo:warning=1 error generated.

    --- stderr


    error occurred: Command env -u IPHONEOS_DEPLOYMENT_TARGET "/Users/you/.local/share/solana/install/releases/1.18.22/solana-release/bin/sdk/sbf/dependencies/platform-tools/llvm/bin/clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-darwin" "-mmacosx-version-min=14.4" "-Wall" "-Wextra" "-std=c11" "-o" "/Users/you/testprogram/target/release/build/blake3-735a4c71d985df30/out/db3b6bfb95261072-blake3_neon.o" "-c" "c/blake3_neon.c" with args clang did not execute successfully (status code exit status: 1).
  ```
</Accordion>

## Guides

<table>
  <colgroup>
    <col style={{ width: "30%" }} />

    <col style={{ width: "70%" }} />
  </colgroup>

  <thead>
    <tr>
      <th />

      <th />
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <a href="/pda/compressed-pdas/guides/how-to-create-compressed-accounts">Create</a>
      </td>

      <td>Initialize compressed PDAs in your program</td>
    </tr>

    <tr>
      <td>
        <a href="/pda/compressed-pdas/guides/how-to-update-compressed-accounts">Update</a>
      </td>

      <td>Modify state in compressed accounts</td>
    </tr>

    <tr>
      <td>
        <a href="/pda/compressed-pdas/guides/how-to-close-compressed-accounts">Close</a>
      </td>

      <td>Reclaim lamports from compressed accounts</td>
    </tr>

    <tr>
      <td>
        <a href="/pda/compressed-pdas/guides/how-to-reinitialize-compressed-accounts">Reinitialize</a>
      </td>

      <td>Reset and reuse compressed accounts</td>
    </tr>

    <tr>
      <td>
        <a href="/pda/compressed-pdas/guides/how-to-burn-compressed-accounts">Burn</a>
      </td>

      <td>Permanently delete compressed accounts</td>
    </tr>

    <tr>
      <td>
        <a href="/pda/compressed-pdas/nullifier-pda">Nullifier PDAs</a>
      </td>

      <td>Prevent replay attacks with one-time use accounts</td>
    </tr>
  </tbody>
</table>

## Program Examples

| Example                                                                                                          | Description                                                                                                                                                           |
| :--------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Account Comparison](https://github.com/Lightprotocol/program-examples/tree/main/account-comparison)             | Compare compressed accounts with standard Solana accounts                                                                                                             |
| [basic-operations/anchor](https://github.com/Lightprotocol/program-examples/tree/main/basic-operations/anchor)   | Anchor programs to create, update, close, reinitialize and burn compressed accounts with Rust and TypeScript tests                                                    |
| [basic-operations/native](https://github.com/Lightprotocol/program-examples/tree/main/basic-operations/native)   | Native Solana program implementation to create, update, close, reinitialize and burn compressed accounts with Rust tests                                              |
| [Counter (Anchor)](https://github.com/Lightprotocol/program-examples/tree/main/counter/anchor)                   | Full compressed account lifecycle (create, increment, decrement, reset, close) using Anchor framework                                                                 |
| [Counter (Native)](https://github.com/Lightprotocol/program-examples/tree/main/counter/native)                   | Native Solana program implementation with Rust tests                                                                                                                  |
| [Counter (Pinocchio)](https://github.com/Lightprotocol/program-examples/tree/main/counter/pinocchio)             | Pinocchio implementation using light-sdk-pinocchio with Rust tests                                                                                                    |
| [Create-and-Update](https://github.com/Lightprotocol/program-examples/tree/main/create-and-update)               | Create new compressed accounts and update existing ones within a single instruction and one validity proof                                                            |
| [merkle-distributor](https://github.com/Lightprotocol/distributor)                                               | SPL token distribution with compressed PDAs for claim tracking, vesting, and clawback                                                                                 |
| [Nullifier Program](https://github.com/Lightprotocol/nullifier-program)                                          | Primitive to enforce that a given onchain instruction (such as a payment) executes only once, and to track execution by unique identifiers (e.g. a nonce, uuid, etc.) |
| [Read-Only](https://github.com/Lightprotocol/program-examples/tree/main/read-only)                               | Create compressed accounts and read them on-chain                                                                                                                     |
| [simple-claim](https://github.com/Lightprotocol/program-examples-airdrop-implementations/tree/main/simple-claim) | Distributes compressed tokens that decompress to SPL on claim                                                                                                         |
| [ZK-ID](https://github.com/Lightprotocol/program-examples/tree/main/zk-id)                                       | Zero-knowledge proofs for identity verification with compressed accounts                                                                                              |
| [ZK-Nullifier](https://github.com/Lightprotocol/program-examples/tree/main/zk-nullifier)                         | Implementation of nullifiers for zk programs on Solana to prevent double spending                                                                                     |

## SDK Reference

### Client

<CardGroup cols={2}>
  <Card title="@lightprotocol/stateless.js" icon="js" href="https://lightprotocol.github.io/light-protocol/stateless.js/index.html">
    TypeScript RPC client for compressed accounts, validity proofs, and address derivation.
  </Card>

  <Card title="light-client" icon="rust" href="https://docs.rs/light-client/latest/light_client/">
    Rust RPC client and indexer for compressed accounts.
  </Card>
</CardGroup>

### Program

<CardGroup cols={2}>
  <Card title="light-sdk" icon="rust" href="https://docs.rs/light-sdk/latest/light_sdk/">
    Core SDK for compressed accounts in Anchor programs.
  </Card>

  <Card title="light-sdk-macros" icon="rust" href="https://docs.rs/light-sdk-macros/latest/light_sdk_macros/">
    Procedural macros for LightAccount derivation.
  </Card>

  <Card title="light-program-test" icon="rust" href="https://docs.rs/crate/light-program-test/latest">
    Local testing framework for programs.
  </Card>
</CardGroup>

# Next Steps

<Card title="Build a client for your program." icon="chevron-right" color="#0066ff" href="/pda/compressed-pdas/guides/client-guide" horizontal />
