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 light_prover_client::prover::ProverConfig;
34//! use solana_pubkey::Pubkey;
35//!
36//! #[tokio::main]
37//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
38//! // Start local test validator with Light Protocol programs
39//! let config = LightValidatorConfig {
40//! enable_indexer: true,
41//! prover_config: Some(ProverConfig::default()),
42//! wait_time: 75,
43//! sbf_programs: vec![],
44//! limit_ledger_size: None,
45//! };
46//! spawn_validator(config).await;
47//!
48//! // Connect to the validator
49//! let mut rpc = LightClient::new(LightClientConfig::local()).await?;
50//!
51//! // Or connect to devnet/mainnet:
52//! // let mut rpc = LightClient::new(LightClientConfig::new("https://devnet.helius-rpc.com/?api-key=YOUR_KEY")).await?;
53//! // let mut rpc = LightClient::new(LightClientConfig::new("https://mainnet.helius-rpc.com/?api-key=YOUR_KEY")).await?;
54//!
55//! let owner = Pubkey::new_unique();
56//!
57//! // Create indexer config for queries
58//! let slot = rpc.get_slot().await?;
59//! let config = IndexerRpcConfig {
60//! slot,
61//! retry_config: RetryConfig::default(),
62//! };
63//!
64//! // Query compressed accounts using Indexer trait
65//! let accounts = rpc
66//! .get_compressed_accounts_by_owner(&owner, None, Some(config))
67//! .await?;
68//!
69//! println!("Found {} compressed accounts", accounts.value.items.len());
70//!
71//! // Get validity proofs for creating transactions
72//! let rpc_result = rpc
73//! .get_validity_proof(
74//! vec![], // add account hashes here
75//! vec![], // add addresses with address tree here
76//! None
77//! )
78//! .await?;
79//!
80//! println!("Got validity proof and proof inputs {:?}", rpc_result.value);
81//!
82//! Ok(())
83//! }
84//! ```
85
86pub mod constants;
87pub mod fee;
88pub mod indexer;
89pub mod local_test_validator;
90pub mod rpc;
91
92/// Reexport for ProverConfig and other types.
93pub use light_prover_client;