wallet_transactions/
wallet_transactions.rs

1//! Wallet Transactions Example
2//!
3//! This example demonstrates how to retrieve a wallet's transaction history.
4//! It shows how to:
5//! - Initialize a Privy client with app credentials
6//! - Query transaction history for specific assets and chains
7//! - Handle pagination with cursors and limits
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`: The wallet ID to get transactions for
13//!
14//! ## Usage
15//! ```bash
16//! cargo run --example wallet_transactions
17//! ```
18
19use anyhow::Result;
20use privy_rs::{
21    PrivyClient,
22    generated::types::{
23        WalletTransactionsAsset, WalletTransactionsAssetString, WalletTransactionsChain,
24    },
25};
26use tracing_subscriber::EnvFilter;
27
28#[tokio::main]
29async fn main() -> Result<()> {
30    tracing_subscriber::fmt()
31        .with_env_filter(
32            EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
33        )
34        .init();
35
36    // Get wallet ID from environment and initialize client
37    let wallet_id =
38        std::env::var("PRIVY_WALLET_ID").expect("PRIVY_WALLET_ID environment variable not set");
39    let client = PrivyClient::new_from_env()?;
40
41    tracing::info!(
42        "initialized privy client from environment, wallet_id: {}",
43        wallet_id
44    );
45
46    // Get SOL transactions on Solana mainnet
47    let transactions = client
48        .wallets()
49        .transactions()
50        .get(
51            &wallet_id,
52            &WalletTransactionsAsset::String(WalletTransactionsAssetString::Sol),
53            WalletTransactionsChain::Base,
54            None,       // No cursor for first page
55            Some(10.0), // Limit to 10 transactions,
56            None,
57        )
58        .await?;
59
60    tracing::info!("got wallet transactions: {:?}", transactions);
61
62    Ok(())
63}