> ## 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.

# Balances

# Balance Management

This guide covers querying and displaying token balances using the Privacy Boost WASM SDK.

## Basic Usage

```typescript theme={null}
const balance = await sdk.getBalance('0x...token-address');
console.log('Shielded:', balance.shieldedBalance);
console.log('Wallet:', balance.walletBalance);
```

## TokenBalance Type

```typescript theme={null}
interface TokenBalance {
  tokenAddress: string;
  shieldedBalance: string;  // Amount in wei
  walletBalance: string;    // Amount in wei
  symbol?: string;
  decimals: number;
}
```

## Getting All Balances

```typescript theme={null}
const allBalances = await sdk.getAllBalances();
for (const balance of allBalances) {
  const formatted = sdk.formatAmount(balance.shieldedBalance, balance.decimals);
  console.log(`${balance.symbol}: ${formatted} (shielded)`);
}
```

## Formatting Balances

```typescript theme={null}
const balance = await sdk.getBalance(tokenAddress);

const shielded = sdk.formatAmount(balance.shieldedBalance, balance.decimals);
const wallet = sdk.formatAmount(balance.walletBalance, balance.decimals);

console.log(`Shielded: ${shielded} ${balance.symbol}`);
console.log(`Wallet: ${wallet} ${balance.symbol}`);
```

## Token Tracking

The SDK allows you to track specific tokens:

```typescript theme={null}
// Set tracked tokens
sdk.setTrackedTokens(['0x...token1', '0x...token2']);

// Add more tokens
sdk.addTrackedTokens(['0x...token3']);

// Get tracked list
const tracked = sdk.getTrackedTokens();
```

## Error Handling

```typescript theme={null}
try {
  const balance = await sdk.getBalance(tokenAddress);
} catch (error) {
  if (error.message.includes('Not authenticated')) {
    console.log('Please log in first');
  } else if (error.message.includes('Network error')) {
    console.log('Network error, please retry');
  } else {
    console.log('Balance error:', error.message);
  }
}
```

## Best Practices

### 1. Format Balances for Display

Always use `sdk.formatAmount()` to convert wei strings to human-readable values.

### 2. Refresh After Operations

Refresh balances after deposits, withdrawals, or transfers.

### 3. Track Only Relevant Tokens

Use `setTrackedTokens()` to limit balance queries to tokens your app cares about.

## Next Steps

* [Deposits Guide](./deposits)
* [Withdrawals Guide](./withdrawals)
* [Transactions Guide](./transactions)
* [Error Handling](./error-handling)


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