light_client/lib.rs
1//! # Light Client
2//!
3//! A client library for interacting with Light Protocol compressed accounts and RPC endpoints.
4//!
5//! ## Features
6//! - Connect to various RPC endpoints (local test validator, devnet/mainnet)
7//! - Query compressed accounts and validity proofs from RPC endpoints
8//! - Support for both v1 and v2 merkle trees (with v2 feature)
9//! - Start local test validator with Light Protocol programs
10//!
11//! ## Prerequisites
12//!
13//! For local test validator usage, install the Light CLI:
14//! ```bash
15//! npm i -g @lightprotocol/zk-compression-cli
16//! ```
17//!
18//! ## Example
19//!
20//! ```no_run
21//! use light_client::{
22//! rpc::{LightClient, LightClientConfig, Rpc},
23//! indexer::{Indexer, IndexerRpcConfig, RetryConfig},
24//! local_test_validator::{spawn_validator, LightValidatorConfig},
25//! };
26//! use light_prover_client::prover::ProverConfig;
27//! use solana_pubkey::Pubkey;
28//!
29//! #[tokio::main]
30//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
31//! // Start local test validator with Light Protocol programs
32//! let config = LightValidatorConfig {
33//! enable_indexer: true,
34//! prover_config: Some(ProverConfig::default()),
35//! wait_time: 75,
36//! sbf_programs: vec![],
37//! limit_ledger_size: None,
38//! };
39//! spawn_validator(config).await;
40//!
41//! // Connect to the validator
42//! let mut rpc = LightClient::new(LightClientConfig::local()).await?;
43//!
44//! // Or connect to devnet/mainnet with API key:
45//! // let api_key = "your-api-key".to_string();
46//! // let mut rpc = LightClient::new(LightClientConfig::new(
47//! // "https://devnet.helius-rpc.com/?api-key=".to_string(),
48//! // Some("https://devnet.helius-rpc.com".to_string()),
49//! // Some(api_key),
50//! // )).await?;
51//!
52//! let owner = Pubkey::new_unique();
53//!
54//! // Create indexer config for queries
55//! let slot = rpc.get_slot().await?;
56//! let config = IndexerRpcConfig {
57//! slot,
58//! retry_config: RetryConfig::default(),
59//! };
60//!
61//! // Query compressed accounts using Indexer trait
62//! let accounts = rpc
63//! .get_compressed_accounts_by_owner(&owner, None, Some(config))
64//! .await?;
65//!
66//! println!("Found {} compressed accounts", accounts.value.items.len());
67//!
68//! // Get validity proofs for creating transactions
69//! let rpc_result = rpc
70//! .get_validity_proof(
71//! vec![], // add account hashes here
72//! vec![], // add addresses with address tree here
73//! None
74//! )
75//! .await?;
76//!
77//! println!("Got validity proof and proof inputs {:?}", rpc_result.value);
78//!
79//! Ok(())
80//! }
81//! ```
82
83pub mod constants;
84pub mod fee;
85pub mod indexer;
86pub mod local_test_validator;
87pub mod rpc;
88
89/// Reexport for ProverConfig and other types.
90pub use light_prover_client;