The program-examples repository at https://github.com/Lightprotocol/program-examples contains reference implementations demonstrating compressed accounts on Solana using Light Protocol. The repository provides examples from basic CRUD operations to production-ready airdrops, zero-knowledge identity verification, and atomic multi-account operations.
The repository implements three programming models (Anchor, Native Solana, and Pinocchio) with identical counter program logic across all three, enabling direct comparison of developer experience, control level, and performance characteristics.
Key Statistics:
For programming model comparison, see Counter Example. For SDK details, see SDKs and Tools.
Sources: README.md1-127
The repository organizes code into directories by example category, with each containing on-chain programs and test suites:
program-examples/
├── basic-operations/
│ ├── anchor/ # Anchor implementations
│ │ ├── create/, update/, close/, reinit/, burn/
│ └── native/ # Native implementations
│ └── programs/
│ ├── create/, update/, close/, reinit/, burn/
├── counter/
│ ├── anchor/ # Uses light-sdk with anchor feature
│ ├── native/ # Uses light-sdk directly
│ └── pinocchio/ # Uses light-sdk-pinocchio
├── create-and-update/ # Atomic operations example
├── read-only/ # Non-mutating verification
├── account-comparison/ # Compressed vs standard PDAs
├── airdrop-implementations/
│ ├── simple-claim/ # Basic token distribution
│ └── distributor/ # Git submodule: advanced features
└── zk/
├── zk-id/ # Groth16 identity verification
└── nullifier/ # Git submodule: replay prevention
Submodules: Two directories are git submodules pointing to separate repositories:
airdrop-implementations/distributor/ → https://github.com/Lightprotocol/distributor.gitzk/nullifier/ → https://github.com/Lightprotocol/nullifier-program.gitSources: README.md5-58 .gitmodules1-7
The following diagram shows how example programs interact with Light Protocol SDKs and the underlying Solana blockchain:
Key Interactions:
| Component | Code Entity | Purpose |
|---|---|---|
| light-sdk | LightAccount struct with new_init(), new_mut(), new_close(), new_burn(), new_empty(), new_read_only() methods | Primary API for compressed account operations in Anchor and Native programs |
| @lightprotocol/stateless.js | getValidityProofV0(), getCompressedAccount(), createRpc() functions | TypeScript client library for obtaining validity proofs and querying account state |
| CPI Pattern | solana_program::program::invoke() calls to Light System Program | All compressed account state changes execute via Cross-Program Invocation |
| Light System Program | On-chain program managing Merkle trees | Validates proofs, nullifies old leaves, inserts new leaves |
Sources: README.md61-75 Program source files
The repository provides three programming models with different trade-offs:
| Model | Entry Point | Example Path | Characteristics |
|---|---|---|---|
| Anchor | #[program] macro | counter/anchor/programs/counter/src/lib.rs1-200 | Macro-based, IDL generation, type-safe accounts struct |
| Native | entrypoint!(process_instruction) | counter/native/src/lib.rs1-300 | Manual parsing with LightInstructionAccounts::try_from_slice() |
| Pinocchio | Pinocchio framework | counter/pinocchio/src/lib.rs1-250 | Performance-focused SDK variant |
The counter example is the only program implementing all three models with identical business logic, making it the primary reference for model comparison. See Implementation Comparison for detailed analysis.
Sources: README.md31-37 Counter implementation files
The repository provides three distinct programming models, each with different trade-offs:
| Model | SDK | Examples | Characteristics |
|---|---|---|---|
| Anchor | light-sdk with anchor feature | 7 programs | Macros, automatic deserialization, IDL for clients |
| Native | light-sdk | 7 programs | Manual instruction parsing, direct entrypoint!(), fine-grained control |
| Pinocchio | light-sdk-pinocchio | 1 program (counter) | Performance-focused, alternative framework |
The Counter example uniquely implements all three models with identical logic, making it the primary resource for comparing approaches. See Implementation Comparison for detailed analysis.
Sources: README.md14-58
The repository requires specific versions of tooling and dependencies to ensure compatibility with Light Protocol's compressed account system:
| Component | Version | Purpose |
|---|---|---|
| Rust | 1.90.0+ | Primary language for on-chain programs |
| Solana CLI | 2.3.11 | Blockchain interaction and deployment |
| Anchor CLI | 0.31.1 | Anchor framework build and test tooling |
| ZK Compression CLI | 0.27.1-alpha.2+ | Light Protocol project scaffolding via light init |
| Node.js | 23.5.0+ | TypeScript client development and testing |
Sources: README.md76-104
Rust Crates:
light-sdk: Core SDK supporting both Anchor and Native programs. Provides LightAccount API for compressed account operations. See light-sdk documentation for details.light-sdk-pinocchio: Alternative SDK for Pinocchio framework programs with different performance characteristics.light-hasher: Cryptographic hashing utilities optimized for zero-knowledge compression.light-client: RPC client for querying compressed account state and indexer for historical data.light-program-test: Framework for writing integration tests with local validator simulation.NPM Packages:
@lightprotocol/[email protected]: TypeScript client library providing functions like getValidityProofV0(), getCompressedAccount(), and createRpc() for interacting with compressed accounts from JavaScript applications.@lightprotocol/[email protected]: Command-line interface including the light init <project-name> command for scaffolding new projects.Sources: README.md61-89
The following commands install required tooling with pinned versions for compatibility:
Sources: README.md86-104
The repository organizes examples into five categories, progressing from basic operations to advanced use cases.
Sources: README.md5-58
| Category | Programs | Key Features | Documentation |
|---|---|---|---|
| Basic Operations | create, update, close, reinit, burn | Fundamental CRUD operations, both Anchor and Native implementations | See Basic Operations Examples |
| Counter | counter/anchor, counter/native, counter/pinocchio | Full lifecycle with all three programming models, increment/decrement/reset operations | See Counter Example |
| Advanced | create-and-update, read-only, account-comparison | Atomic operations, read-only access, cost comparison demonstrations | See Create-and-Update, Read-Only, Account Comparison |
| Airdrops | simple-claim, distributor (submodule) | Token distribution systems with compressed accounts, 40-200x cost reduction vs standard Solana | See Airdrop Implementations |
| Zero-Knowledge | zk-id, nullifier (submodule) | Privacy-preserving identity verification, replay attack prevention | See ZK Programs |
Implementation Coverage:
Sources: README.md7-58
The repository uses GitHub Actions workflows defined in .github/workflows/ to validate all examples:
Test Environment Configuration:
| Workflow | Command | Environment |
|---|---|---|
| rust-tests.yml | cargo test-sbf -p <package> | Solana CLI 2.3.11, Rust 1.90.0 |
| typescript-tests.yml | anchor test | Solana CLI 2.3.11, Rust 1.90.0, Node.js 22, Anchor 0.31.1, light test-validator |
The TypeScript workflow spawns a light test-validator process which bundles:
All workflows use fail-fast: false in their matrix strategy, ensuring all test jobs complete even if one fails.
Sources: .github/workflows/rust-tests.yml1-62 .github/workflows/typescript-tests.yml .github/workflows/trigger-docs-sync.yml
To scaffold a new compressed account program:
The light init command creates a template Solana program pre-configured with compressed account support, including:
light-program-testFor step-by-step instructions, see Getting Started. For detailed development workflows, see Development Guide.
Sources: README.md106-119
Refresh this wiki