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:
45//! // let mut rpc = LightClient::new(LightClientConfig::new("https://devnet.helius-rpc.com/?api-key=YOUR_KEY")).await?;
46//! // let mut rpc = LightClient::new(LightClientConfig::new("https://mainnet.helius-rpc.com/?api-key=YOUR_KEY")).await?;
47//!
48//! let owner = Pubkey::new_unique();
49//!
50//! // Create indexer config for queries
51//! let slot = rpc.get_slot().await?;
52//! let config = IndexerRpcConfig {
53//! slot,
54//! retry_config: RetryConfig::default(),
55//! };
56//!
57//! // Query compressed accounts using Indexer trait
58//! let accounts = rpc
59//! .get_compressed_accounts_by_owner(&owner, None, Some(config))
60//! .await?;
61//!
62//! println!("Found {} compressed accounts", accounts.value.items.len());
63//!
64//! // Get validity proofs for creating transactions
65//! let rpc_result = rpc
66//! .get_validity_proof(
67//! vec![], // add account hashes here
68//! vec![], // add addresses with address tree here
69//! None
70//! )
71//! .await?;
72//!
73//! println!("Got validity proof and proof inputs {:?}", rpc_result.value);
74//!
75//! Ok(())
76//! }
77//! ```
78
79pub mod constants;
80pub mod fee;
81pub mod indexer;
82pub mod local_test_validator;
83pub mod rpc;
84
85/// Reexport for ProverConfig and other types.
86pub use light_prover_client;