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