get_wallets/
get_wallets.rs

1//! Get Wallets Example
2//!
3//! This example demonstrates how to retrieve all wallets in your Privy app.
4//! It shows how to:
5//! - Initialize a Privy client with app credentials
6//! - List all wallets with optional pagination
7//! - Handle the response containing wallet data
8//!
9//! ## Required Environment Variables
10//! - `PRIVY_APP_ID`: Your Privy app ID
11//! - `PRIVY_APP_SECRET`: Your Privy app secret
12//! - `PRIVY_WALLET_ID`: Target wallet ID (for logging purposes)
13//! - `PRIVY_PUBLIC_KEY`: Solana public key (for logging purposes)
14//!
15//! ## Usage
16//! ```bash
17//! cargo run --example get_wallets
18//! ```
19
20use anyhow::Result;
21use privy_rs::PrivyClient;
22use tracing_subscriber::EnvFilter;
23
24#[tokio::main]
25async fn main() -> Result<()> {
26    tracing_subscriber::fmt()
27        .with_env_filter(
28            EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
29        )
30        .init();
31
32    // Get additional environment variables and initialize client
33    let wallet_id =
34        std::env::var("PRIVY_WALLET_ID").expect("PRIVY_WALLET_ID environment variable not set");
35    let public_key =
36        std::env::var("PRIVY_PUBLIC_KEY").expect("PRIVY_PUBLIC_KEY environment variable not set");
37    let client = PrivyClient::new_from_env()?;
38
39    tracing::info!(
40        "initialized privy client from environment, wallet_id: {}, public_key: {}",
41        wallet_id,
42        public_key
43    );
44
45    let wallets = client.wallets().list(None, None, Some(5.0), None).await?;
46
47    tracing::info!("got wallets: {:?}", wallets);
48
49    Ok(())
50}