SDK Library Structure
The Light Protocol SDK is organized into focused libraries, each serving a specific purpose in the development stack.light-sdk
Cargo.toml
Core Modules
account
Compressed account abstraction similar to Anchor’sAccount.
Create a new compressed account for initializationParameters:
program_id: &Pubkey- Program that owns the accountaddress: Option<[u8; 32]>- Optional address for the accounttree_index: u8- Index of the state tree to use
Load existing compressed account for mutationParameters:
program_id: &Pubkey- Program that owns the accountmeta: &CompressedAccountMeta- Account metadata from instructiondata: T- Deserialized account data
Load compressed account for closingParameters:
program_id: &Pubkey- Program that owns the accountmeta: &CompressedAccountMeta- Account metadata from instructiondata: T- Deserialized account data
address
Functions to derive compressed account addresses.Derive a deterministic address for a compressed accountParameters:
seeds: &[&[u8]]- Seed bytes for derivationaddress_tree: &Pubkey- Address Merkle tree pubkeyprogram_id: &Pubkey- Owner program ID
([u8; 32], [u8; 32]) - Address and address seedcpi
Utilities to invoke the Light System Program via CPI.Parses remaining accounts for Light System Program CPIFields:
fee_payer: &AccountInfo- Transaction fee payerremaining_accounts: &[AccountInfo]- All remaining accountscpi_signer: CpiSigner- Program’s CPI authority
Builder for Light System Program CPI instructionsMethods:
new_cpi(signer, proof)- Create new CPI instructionmode_v1()/mode_v2()- Set Merkle tree versionwith_light_account(account)- Add compressed accountwith_new_addresses(params)- Add new addressesinvoke(accounts)- Execute the CPI
instruction
Types for building instructions with compressed accounts.Metadata for a compressed account in instruction dataFields:
hash: [u8; 32]- Account data hashaddress: Option<[u8; 32]>- Account address (if any)tree_index: u8- Index of the state treeleaf_index: u32- Leaf index in the tree
Zero-knowledge proof that verifies compressed account state exists and new addresses don’t existSize: 128 bytes (constant for any number of accounts)Obtained from: RPC
getValidityProof methodCompact representation of address tree information for instruction dataFields:
tree_index: u8- Index of address tree in remaining accountsaddress_tree_offset: u8- Offset to address tree accounts
Macros
LightDiscriminator
Derive a discriminator for compressed account types.LightHasher
Derive a hasher implementation for compressed accounts.derive_light_cpi_signer!
Generate CPI signer constant from program ID.Dependencies
Key dependencies inlight-sdk:
light-client
Cargo.toml
Core Modules
rpc
RPC client for Solana and Photon indexer.Combined Solana RPC and Photon indexer clientMethods:
new(config)- Create new clientget_slot()- Get current slotget_balance(pubkey)- Get account balance- Standard Solana RPC methods
- Photon indexer methods (via
Indexertrait)
Configuration for Light client connectionsMethods:
local()- Connect to local test validatornew(rpc_url, photon_url)- Custom RPC endpoints
indexer
Query compressed accounts from Photon indexer.Trait for querying compressed accountsMethods:
get_compressed_accounts_by_owner(owner, cursor, config)- Query by ownerget_compressed_account(hash, config)- Get single accountget_validity_proof(hashes, addresses, config)- Get validity proofget_multiple_compressed_accounts(hashes, config)- Batch query
local_test_validator
Spawn local test validator with Light Protocol programs.Configuration for local test validatorFields:
enable_indexer: bool- Start Photon indexerenable_prover: bool- Start prover serverwait_time: u64- Seconds to wait for servicessbf_programs: Vec<(String, Pubkey)>- Custom programs to deploylimit_ledger_size: Option<u64>- Limit ledger sizeuse_surfpool: bool- Use surfpool prover service
Dependencies
Key dependencies inlight-client:
light-token
Cargo.toml
Core Modules
instruction
Instruction builders and CPI functions for token operations.Available CPI Builders
CreateMintCpi
CreateMintCpi
Create a new Light mintParameters:
authority: &Pubkey- Mint authoritymint: &Pubkey- Mint addressdecimals: u8- Token decimalsmetadata: Option<TokenMetadata>- Token metadata
CreateAssociatedAccountCpi
CreateAssociatedAccountCpi
Create associated token accountParameters:
payer: &Pubkey- Transaction payerowner: &Pubkey- Token account ownermint: &Pubkey- Token mint
CreateTokenAccountCpi
CreateTokenAccountCpi
Create token account with custom addressParameters:
payer: &Pubkey- Transaction payerowner: &Pubkey- Token account ownermint: &Pubkey- Token mintaccount: &Pubkey- Account address
MintToCpi / MintToCheckedCpi
MintToCpi / MintToCheckedCpi
Mint tokens to accountParameters:
mint: &Pubkey- Token mintdestination: &Pubkey- Destination accountauthority: &Pubkey- Mint authorityamount: u64- Amount to mintdecimals: u8- Token decimals (checked variant)
TransferCpi / TransferCheckedCpi
TransferCpi / TransferCheckedCpi
Transfer tokens between accountsParameters:
from: &Pubkey- Source accountto: &Pubkey- Destination accountauthority: &Pubkey- Transfer authoritymint: &Pubkey- Token mintamount: u64- Amount to transferdecimals: u8- Token decimals (checked variant)
TransferInterfaceCpi
TransferInterfaceCpi
Transfer with automatic account type detectionAuto-detects: SPL token accounts, Light token accounts, compressed token accountsParameters:
from: &Pubkey- Source accountto: &Pubkey- Destination accountauthority: &Pubkey- Transfer authoritymint: &Pubkey- Token mintamount: u64- Amount to transfer
BurnCpi / BurnCheckedCpi
BurnCpi / BurnCheckedCpi
Burn tokens from accountParameters:
account: &Pubkey- Token accountmint: &Pubkey- Token mintauthority: &Pubkey- Burn authorityamount: u64- Amount to burndecimals: u8- Token decimals (checked variant)
ApproveCpi
ApproveCpi
Approve delegate for token accountParameters:
account: &Pubkey- Token accountdelegate: &Pubkey- Delegate addressowner: &Pubkey- Account owneramount: u64- Approved amount
RevokeCpi
RevokeCpi
Revoke delegate approvalParameters:
account: &Pubkey- Token accountowner: &Pubkey- Account owner
FreezeCpi / ThawCpi
FreezeCpi / ThawCpi
Freeze or thaw token accountParameters:
account: &Pubkey- Token accountmint: &Pubkey- Token mintauthority: &Pubkey- Freeze authority
CloseAccountCpi
CloseAccountCpi
Close token account and reclaim rentParameters:
account: &Pubkey- Token account to closedestination: &Pubkey- Recipient of remaining lamportsowner: &Pubkey- Account owner
Constants
Dependencies
Key dependencies inlight-token:
Supporting Libraries
light-program-test
Purpose: Fast local test environment using LiteSVMlight-sdk-macros
Purpose: Procedural macros for compressed accounts#[derive(LightDiscriminator)]- 8-byte discriminator for account types#[derive(LightHasher)]- Hash implementation for Merkle tree state#[derive(AnchorDiscriminator)]- Anchor-compatible discriminatorderive_light_cpi_signer!()- Generate CPI signer from program IDderive_light_rent_sponsor!()- Generate rent sponsor PDA
photon-api
Purpose: API client for Photon indexerVersion Information
All SDK libraries are versioned together at 0.23.0 to ensure compatibility.
Workspace Dependencies
FromCargo.toml:
Next Steps
Program Integration
Learn how to integrate Light SDK into your Solana programs
Testing Guide
Set up testing for compressed account programs