create_wallet/create_wallet.rs
1//! Create Wallet Example
2//!
3//! This example demonstrates how to create a new embedded wallet for a user.
4//! It shows how to:
5//! - Initialize a Privy client with app credentials
6//! - Create a wallet for a specific user with chain configuration
7//! - Handle the response containing the new 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_USER_ID`: The user ID to create a wallet for
13//!
14//! ## Usage
15//! ```bash
16//! cargo run --example create_wallet
17//! ```
18
19use anyhow::Result;
20use privy_rs::{
21 PrivyClient,
22 generated::types::{CreateWalletBody, WalletChainType},
23};
24use tracing_subscriber::EnvFilter;
25
26#[tokio::main]
27async fn main() -> Result<()> {
28 tracing_subscriber::fmt()
29 .with_env_filter(
30 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
31 )
32 .init();
33
34 // Initialize client from environment variables
35 let client = PrivyClient::new_from_env()?;
36
37 tracing::info!("initialized privy client from environment");
38
39 let wallet = client
40 .wallets()
41 .create(
42 None,
43 &CreateWalletBody {
44 chain_type: WalletChainType::Solana,
45 additional_signers: None,
46 owner: None,
47 owner_id: None,
48 policy_ids: vec![],
49 },
50 )
51 .await?;
52
53 tracing::info!("got new wallet: {:?}", wallet);
54
55 Ok(())
56}