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

# Balance

# getBalanceFromUtxos()

`getBalanceFromUtxos()` is a utility function from `privacycash/utils` used to calculate the total balance from a set of SOL UTXOs (Unspent Transaction Outputs).

## Parameters

| Parameter | Type     | Description                                                       |
| :-------- | :------- | :---------------------------------------------------------------- |
| `utxos`   | `Utxo[]` | An array of UTXO objects, typically retrieved using `getUtxos()`. |

## Return Value

The function returns an object containing the balance information:

| Property   | Type     | Description                    |
| :--------- | :------- | :----------------------------- |
| `lamports` | `number` | The total balance in lamports. |

## Example Usage

```typescript theme={null}
import { getUtxos, getBalanceFromUtxos } from "privacycash/utils"

// 1. Fetch user UTXOs
const myValidUtxos = await getUtxos({
    connection,
    publicKey,
    storage: localStorage,
    encryptionService,
});

// 2. Calculate balance
const balanceInfo = getBalanceFromUtxos(myValidUtxos);
console.log("Total SOL Balance (lamports):", balanceInfo.lamports);
```

***

# getUtxos()

`getUtxos()` is used to fetch all valid private UTXOs for a given user.

## Parameters

| Parameter           | Type                | Description                                  |
| :------------------ | :------------------ | :------------------------------------------- |
| `connection`        | `Connection`        | Solana web3 connection object.               |
| `publicKey`         | `PublicKey`         | The user's Solana public key.                |
| `storage`           | `Storage`           | A storage object (e.g., `localStorage`).     |
| `encryptionService` | `EncryptionService` | The encryption service to decrypt UTXO data. |
| `offset`            | `number`            | (optional) utxo fetch offset                 |

## Example Usage

```typescript theme={null}
const myValidUtxos = await getUtxos({
    connection,
    publicKey,
    storage: localStorage,
    encryptionService,
});
```

***

# getBalanceFromUtxosSPL()

`getBalanceFromUtxosSPL()` calculates the total balance from a set of SPL token UTXOs.

## Parameters

| Parameter | Type     | Description                                                |
| :-------- | :------- | :--------------------------------------------------------- |
| `utxos`   | `Utxo[]` | An array of UTXO objects, retrieved using `getUtxosSPL()`. |

## Return Value

| Property     | Type     | Description                      |
| :----------- | :------- | :------------------------------- |
| `base_units` | `number` | The total balance in base units. |

***

# getUtxosSPL()

`getUtxosSPL()` is used to fetch all valid private SPL token UTXOs for a given user and specific token mint.

## Parameters

| Parameter           | Type                  | Description                              |
| :------------------ | :-------------------- | :--------------------------------------- |
| `connection`        | `Connection`          | Solana web3 connection object.           |
| `publicKey`         | `PublicKey`           | The user's Solana public key.            |
| `storage`           | `Storage`             | A storage object (e.g., `localStorage`). |
| `encryptionService` | `EncryptionService`   | The encryption service.                  |
| `mintAddress`       | `PublicKey or string` | The mint address of the SPL token.       |
| `offset`            | `number`              | (optional) utxo fetch offset             |

## Example Usage

```typescript theme={null}
import { getUtxosSPL, getBalanceFromUtxosSPL } from "privacycash/utils"

const myValidUtxos = await getUtxosSPL({
    connection,
    publicKey,
    storage: localStorage,
    encryptionService,
    mintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' // USDC
});

const balanceInfo = getBalanceFromUtxosSPL(myValidUtxos);
console.log("Total USDC Balance (base units):", balanceInfo.base_units);
```
