Introduction
The Light Protocol Rust SDK enables developers to build Solana programs that use ZK Compression for rent-free accounts. The SDK provides libraries for creating compressed accounts, managing state in Merkle trees, and integrating with Light Protocol’s on-chain programs.Core SDK Crates
The Rust SDK consists of three main libraries:light-sdk
Core SDK for building compressed account programs
light-client
RPC client for querying compressed accounts
light-token
SDK for Light Token operations
light-sdk
Version: 0.23.0Crate:
light-sdk
The base library for using Compressed Accounts in Solana on-chain Rust and Anchor programs.
Key Features
- No rent exemption - Compressed accounts don’t require rent-exemption payments
- Constant proof size - 128-byte validity proof per transaction for one or multiple compressed accounts
- Merkle tree state - Account state stored as hashes in State Merkle trees
- Address management - Unique addresses stored in Address Merkle trees
- Framework support - Works with native Solana programs, Anchor, and Pinocchio
When to Use Compressed Accounts
Good for:
- User-owned accounts
- Account data sent as instruction data
- Applications where accounts are accessed individually
- Config accounts that are frequently read
- Pool accounts requiring concurrent access
- DeFi protocols needing parallel execution
Installation
Add to yourCargo.toml:
Available Features
Enables Anchor framework support with
AnchorSerialize/AnchorDeserialize traitsSupport for optimized v2 light system program instructions (available on devnet/localnet)
Enables batched compressed account operations across multiple CPIs with one validity proof
Use Poseidon hash function for state compression
Use Keccak hash function for state compression
Use SHA256 hash function for state compression
light-client
Version: 0.23.0Crate:
light-client
Rust client library for interacting with Light Protocol compressed accounts and RPC endpoints.
Key Features
- Connect to local test validator, devnet, or mainnet
- Query compressed accounts by owner, address, or hash
- Get validity proofs for creating transactions
- Support for both v1 and v2 merkle trees
- Local test validator management
Installation
Quick Example
light-token
Version: 0.23.0Crate:
light-token
SDK for building programs that interact with Light Token Accounts and Light Mints.
Light Token Accounts
- Functionally equivalent to SPL token accounts
- Can hold tokens of Light, SPL, and Token 2022 mints
- Cost: 17,288 lamports to create with 24 hours rent
- Rent-free: Rent exemption sponsored by the token program (388 lamports per 1.5h epoch)
- Auto-compression: Auto-compresses when lamport balance is insufficient
- State preservation: Compressed state is cryptographically preserved on-chain
Installation
Common Operations
| Operation | Instruction Builder | CPI Builder |
|---|---|---|
| Create Associated Token Account | CreateAssociatedTokenAccount | CreateAssociatedAccountCpi |
| Create Token Account | CreateTokenAccount | CreateTokenAccountCpi |
| Transfer | Transfer | TransferCpi |
| Transfer Interface | TransferInterface | TransferInterfaceCpi |
| Create Mint | CreateMint | CreateMintCpi |
| Mint To | MintTo | MintToCpi |
| Burn | Burn | BurnCpi |
| Close Account | CloseAccount | CloseAccountCpi |
Supporting Libraries
light-program-test
Version: 0.23.0Purpose: Fast local test environment using LiteSVM
light-sdk-macros
Version: 0.23.0Purpose: Procedural macros for Light Protocol development
#[derive(LightDiscriminator)]- Derive compressed account discriminator#[derive(LightHasher)]- Derive account hasherderive_light_cpi_signer!()- Generate CPI signer from program ID
Architecture Overview
Version Compatibility
All Light Protocol SDK crates are versioned together at 0.23.0. Make sure to use matching versions across all dependencies.
| SDK Version | Solana Version | Features |
|---|---|---|
| 0.23.0 | 2.3 | V2 Merkle trees, CPI context |
| 0.22.0 | 2.2 | V1 Merkle trees |
Resources
Program Examples
Full example programs using Light SDK
Light Token Examples
Token-specific example programs
API Documentation
Complete API reference on docs.rs
Light CLI
Local test validator with Light Protocol
Next Steps
SDK Libraries Reference
Detailed documentation for each SDK crate
Program Integration
Integrate Light SDK into your Solana program