Light Client
A client library for interacting with Light Protocol compressed accounts and RPC endpoints.
For detailed documentation, visit zkcompression.com.
For full program examples, see the Program Examples.
For pinocchio solana program development see light-sdk-pinocchio.
For rust client developement see light-client.
For rust program testing see light-program-test.
For local test validator with light system programs see Light CLI.
Features
- Connect to various RPC endpoints (local test validator, devnet/mainnet)
- Query compressed accounts and validity proofs from RPC endpoints
- Support for both v1 and v2 merkle trees (with v2 feature)
- Start local test validator with Light Protocol programs
Prerequisites
For local test validator usage, install the Light CLI:
npm i -g @lightprotocol/zk-compression-cli
Example
use light_client::{
rpc::{LightClient, LightClientConfig, Rpc},
indexer::{Indexer, IndexerRpcConfig, RetryConfig},
local_test_validator::{spawn_validator, LightValidatorConfig},
};
use solana_pubkey::Pubkey;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = LightValidatorConfig {
enable_indexer: true,
enable_prover: true,
wait_time: 75,
sbf_programs: vec![],
upgradeable_programs: vec![],
limit_ledger_size: None,
use_surfpool: true,
};
spawn_validator(config).await;
let mut rpc = LightClient::new(LightClientConfig::local()).await?;
let owner = Pubkey::new_unique();
let slot = rpc.get_slot().await?;
let config = IndexerRpcConfig {
slot,
retry_config: RetryConfig::default(),
};
let accounts = rpc
.get_compressed_accounts_by_owner(&owner, None, Some(config))
.await?;
println!("Found {} compressed accounts", accounts.value.items.len());
let rpc_result = rpc
.get_validity_proof(
vec![], vec![], None
)
.await?;
println!("Got validity proof and proof inputs {:?}", rpc_result.value);
Ok(())
}