> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privacyboost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Withdrawals

# Withdrawals

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

## Basic Withdrawal

```typescript theme={null}
const result = await sdk.unshield({
  tokenAddress: '0x...token-address',
  amount: '500000000000000000', // 0.5 tokens in wei
  recipient: '0x...recipient-address',
});
console.log('Withdraw TX:', result.txHash);
```

## Withdrawal Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `tokenAddress` | `string` | Yes | ERC-20 token contract address |
| `amount` | `string` | Yes | Amount in wei (as string) |
| `recipient` | `string` | Yes | Recipient Ethereum address |

## Withdrawal Result

```typescript theme={null}
interface UnshieldResult {
  txHash: string;         // Transaction hash
  amount: string;         // Amount withdrawn
}
```

## WETH Unwrapping

WETH unwrapping is a separate step after the withdrawal settles on-chain.
Call `unwrapWeth()` once the withdrawal is confirmed:

```typescript theme={null}
// Step 1: Unshield WETH from the privacy pool
const result = await sdk.unshield({
  tokenAddress: '0x4200000000000000000000000000000000000006', // WETH
  amount: '1000000000000000000', // 1 WETH
  recipient,
});
console.log('Withdraw TX:', result.txHash);

// Step 2: After withdrawal settles on-chain, unwrap WETH to ETH
// The connected wallet must match the recipient address
const unwrapTxHash = await sdk.unwrapWeth(
  '1000000000000000000',
  recipient,
);
console.log('Unwrap TX:', unwrapTxHash);
```

## Withdraw to Self

```typescript theme={null}
const walletAddress = sdk.walletAddress;
if (walletAddress) {
  const result = await sdk.unshield({
    tokenAddress,
    amount,
    recipient: walletAddress,
  });
}
```

## Error Handling

```typescript theme={null}
try {
  const result = await sdk.unshield({ tokenAddress, amount, recipient });
} catch (error) {
  if (error.message.includes('Insufficient balance')) {
    console.log('Not enough shielded balance');
  } else if (error.message.includes('Invalid privacy address') || error.message.includes('Invalid address')) {
    console.log('Invalid recipient address');
  } else if (error.message.includes('Network error')) {
    console.log('Network error, please retry');
  } else {
    console.log('Withdrawal failed:', error.message);
  }
}
```

## Best Practices

### 1. Default to Self-Withdrawal

Pre-fill the recipient with `sdk.walletAddress` for the most common use case.

### 2. Use Separate Unwrap for ETH

When users want to receive native ETH, withdraw WETH first and then call `unwrapWeth()` after the withdrawal settles on-chain.

### 3. Refresh Balance After Withdrawal

```typescript theme={null}
const result = await sdk.unshield({ tokenAddress, amount, recipient });
const balance = await sdk.getBalance(tokenAddress);
console.log('Remaining shielded:', balance.shieldedBalance);
```

## Next Steps

* [Deposits Guide](./deposits)
* [Transfers Guide](./transfers)
* [Balances Guide](./balances)
* [Error Handling](./error-handling)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.