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

# Swift Balances & History

> Read wallet balance and transaction history data with the Swift OMS Wallet SDK.

Use `oms.indexer` for wallet balance and transaction history reads. Requests use the publishable key configured on `OMSClient`, and balance amounts are returned as raw base-unit strings.

Pass explicit SDK `Network` values with `networks`, or omit `networks` and use `networkType`. When both are omitted, the indexer request defaults to mainnets.

## Get Balances

```swift theme={null}
guard let walletAddress = oms.wallet.walletAddress else { return }

let result = try await oms.indexer.getBalances(
    GetBalancesParams(
        walletAddress: walletAddress,
        networks: [.polygon],
        contractAddresses: ["0x2222222222222222222222222222222222222222"],
        includeMetadata: true
    )
)

for balance in result.nativeBalances {
    print(balance.symbol ?? "", balance.balance ?? "0")
}

for balance in result.balances {
    print(balance.contractAddress ?? "", balance.balance ?? "0")
}
```

**Parameters**

| Parameter           | Type                          | Description                                                                                   |
| ------------------- | ----------------------------- | --------------------------------------------------------------------------------------------- |
| `walletAddress`     | `String`                      | Wallet address to inspect. This can be the active non-custodial wallet or any wallet address. |
| `networks`          | `[Network]?`                  | Explicit SDK network values, such as `[.polygon]`.                                            |
| `networkType`       | `IndexerNetworkType?`         | Network group used when `networks` is omitted. Defaults to `.mainnets`.                       |
| `contractAddresses` | `[String]?`                   | Optional token contract address filters. Omit them to query balances across contracts.        |
| `includeMetadata`   | `Bool`                        | Whether token metadata should be included. Defaults to `true`.                                |
| `omitPrices`        | `Bool?`                       | Whether price fields should be omitted.                                                       |
| `tokenIds`          | `[String]?`                   | Optional token ID filter.                                                                     |
| `contractStatus`    | `ContractVerificationStatus?` | Optional contract verification filter.                                                        |
| `page`              | `TokenBalancesPageRequest?`   | Optional pagination request. Defaults to page `0` with up to `40` entries.                    |

**Returns**

`getBalances` returns `BalancesResult`.

| Field            | Type                 | Description                                      |
| ---------------- | -------------------- | ------------------------------------------------ |
| `status`         | `Int`                | HTTP status code from the indexer response.      |
| `page`           | `TokenBalancesPage?` | Pagination metadata from the indexer response.   |
| `nativeBalances` | `[TokenBalance]`     | Native token balances returned for the wallet.   |
| `balances`       | `[TokenBalance]`     | Token contract balances returned for the wallet. |

## Get Transaction History

```swift theme={null}
guard let walletAddress = oms.wallet.walletAddress else { return }

let history = try await oms.indexer.getTransactionHistory(
    GetTransactionHistoryParams(
        walletAddress: walletAddress,
        networks: [.polygon],
        includeMetadata: true
    )
)

for transaction in history.transactions {
    print(transaction.txnHash, transaction.timestamp)
}
```

**Parameters**

| Parameter            | Type                        | Description                                                                           |
| -------------------- | --------------------------- | ------------------------------------------------------------------------------------- |
| `walletAddress`      | `String`                    | Wallet address whose history should be fetched.                                       |
| `networks`           | `[Network]?`                | Explicit SDK network values.                                                          |
| `networkType`        | `IndexerNetworkType?`       | Network group used when `networks` is omitted. Defaults to `.mainnets`.               |
| `contractAddresses`  | `[String]?`                 | Optional contract address filters.                                                    |
| `transactionHashes`  | `[String]?`                 | Optional transaction hash filters.                                                    |
| `metaTransactionIds` | `[String]?`                 | Optional wallet transaction ID filters, such as `txnId` returned by transaction APIs. |
| `fromBlock`          | `Int?`                      | Optional starting block number.                                                       |
| `toBlock`            | `Int?`                      | Optional ending block number.                                                         |
| `tokenId`            | `String?`                   | Optional token ID filter.                                                             |
| `includeMetadata`    | `Bool`                      | Whether token and contract metadata should be included. Defaults to `true`.           |
| `omitPrices`         | `Bool?`                     | Whether price fields should be omitted.                                               |
| `metadataOptions`    | `MetadataOptions?`          | Optional metadata enrichment filters.                                                 |
| `page`               | `TokenBalancesPageRequest?` | Optional pagination request.                                                          |

**Returns**

`getTransactionHistory` returns `TransactionHistoryResult`.

| Field          | Type                 | Description                                    |
| -------------- | -------------------- | ---------------------------------------------- |
| `status`       | `Int`                | HTTP status code from the indexer response.    |
| `page`         | `TokenBalancesPage?` | Pagination metadata from the indexer response. |
| `transactions` | `[Transaction]`      | Transactions returned for the wallet.          |

## Token Balance Shape

Each `TokenBalance` can include:

| Field                | Type                 | Description                                                                      |
| -------------------- | -------------------- | -------------------------------------------------------------------------------- |
| `contractType`       | `String?`            | Token contract type, such as ERC20, ERC721, or `NATIVE`.                         |
| `contractAddress`    | `String?`            | Token contract address. Native token balances do not include a contract address. |
| `accountAddress`     | `String?`            | Wallet address queried.                                                          |
| `tokenId`            | `String?`            | Token ID for token types that use IDs.                                           |
| `name`               | `String?`            | Token name when returned by the indexer.                                         |
| `symbol`             | `String?`            | Token symbol when returned by the indexer.                                       |
| `balance`            | `String?`            | Raw base-unit balance as a string.                                               |
| `balanceUSD`         | `String?`            | Balance value in USD when price data is returned.                                |
| `priceUSD`           | `String?`            | Token price in USD when price data is returned.                                  |
| `priceUpdatedAt`     | `String?`            | Timestamp for the returned price data.                                           |
| `blockHash`          | `String?`            | Block hash for the balance snapshot.                                             |
| `blockNumber`        | `Int64?`             | Block number for the balance snapshot.                                           |
| `chainId`            | `Int64?`             | Numeric chain ID.                                                                |
| `uniqueCollectibles` | `String?`            | Unique collectible count for NFT summary rows.                                   |
| `isSummary`          | `Bool?`              | Whether the row is a summary balance.                                            |
| `contractInfo`       | `TokenContractInfo?` | Contract metadata when `includeMetadata` is true.                                |
| `tokenMetadata`      | `TokenMetadata?`     | Token metadata when `includeMetadata` is true.                                   |

## Transaction Shape

Each `Transaction` can include:

| Field         | Type                     | Description                                             |
| ------------- | ------------------------ | ------------------------------------------------------- |
| `txnHash`     | `String`                 | Onchain transaction hash.                               |
| `blockNumber` | `Int64`                  | Block number.                                           |
| `blockHash`   | `String`                 | Block hash.                                             |
| `chainId`     | `Int64`                  | Numeric chain ID.                                       |
| `metaTxnId`   | `String?`                | Wallet transaction ID when available.                   |
| `transfers`   | `[TransactionTransfer]?` | Token and native transfers detected in the transaction. |
| `timestamp`   | `String`                 | Transaction timestamp.                                  |
