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