Skip to main content

Withdrawals

This guide covers withdrawing tokens from your private balance back to a wallet address using the Privacy Boost CLI.

CLI Command

privacy-boost withdraw \
  --token 0x4200000000000000000000000000000000000006 \
  --amount 0.5 \
  --recipient 0x1234567890123456789012345678901234567890 \
  --human
Output:
Building proof... (this may take a moment)
Proof generated successfully
Withdraw submitted!
Transaction: 0x5678...9abc
Amount: 0.5 ETH
Recipient: 0x1234...7890

Command Parameters

FlagRequiredDescription
--tokenYesERC-20 token contract address
--amountYesAmount to withdraw
--recipientYesRecipient Ethereum address
--humanNoInterpret amount as human-readable (default: wei)

Programmatic Usage (Rust)

let result = sdk.unshield(
    "0x4200000000000000000000000000000000000006",
    "500000000000000000", // 0.5 tokens in wei
    "0x1234567890123456789012345678901234567890",
)?;
println!("Withdraw TX: {}", result.tx_hash);
println!("Fee: {}", result.fee);

UnshieldResult

pub struct UnshieldResult {
    pub tx_hash: String,
    pub fee: String,
}

Withdraw to Self

Withdraw to the connected wallet:
privacy-boost withdraw \
  --token $TOKEN \
  --amount 0.5 \
  --recipient $(privacy-boost status --json | jq -r .wallet_address) \
  --human
Programmatically:
let wallet = sdk.get_wallet_address().unwrap();
let result = sdk.unshield(token_address, amount, &wallet)?;

Error Handling

match sdk.unshield(token_address, amount, recipient) {
    Ok(result) => println!("Withdraw TX: {}", result.tx_hash),
    Err(CliError::InsufficientBalance) => println!("Not enough shielded balance"),
    Err(CliError::InvalidAddress) => println!("Invalid recipient address"),
    Err(CliError::NotAuthenticated) => println!("Please login first"),
    Err(CliError::NetworkError { message }) => println!("Network error: {}", message),
    Err(e) => println!("Withdrawal failed: {:?}", e),
}

Best Practices

1. Check Shielded Balance First

privacy-boost balance --token $TOKEN
privacy-boost withdraw --token $TOKEN --amount 0.5 --recipient $ADDR --human

2. Use --human for Readability

Avoid mistakes with large wei numbers by using human-readable amounts.

Next Steps