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