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

# Wallet Management Functions

## Wallet Access

### userWallets

Get the current list of user wallets (synchronous).

```kotlin theme={"system"}
val wallets: List<BaseWallet> = sdk.wallets.userWallets
```

#### Example

```kotlin theme={"system"}
val wallets = sdk.wallets.userWallets
wallets.forEach { wallet ->
    println("${wallet.address} (${wallet.chain})")
}
```

### userWalletsChanges

Observe wallet list changes (reactive flow).

```kotlin theme={"system"}
val userWalletsChanges: StateFlow<List<BaseWallet>>
```

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    sdk.wallets.userWalletsChanges.collect { wallets ->
        // Handle wallet changes
        _wallets.value = wallets
    }
}
```

## Balance Operations

### getBalance

Get the balance for a specific wallet.

```kotlin theme={"system"}
suspend fun getBalance(wallet: BaseWallet): String
```

#### Parameters

* **wallet** (BaseWallet): The wallet to check balance for

#### Returns

* **String**: Balance as a string (in native token units)

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val balance = sdk.wallets.getBalance(wallet)
        println("Balance: $balance")
    } catch (e: Exception) {
        println("Failed to get balance: ${e.message}")
    }
}
```

## Network Operations

### getNetwork

Get the current network for a wallet.

```kotlin theme={"system"}
suspend fun getNetwork(wallet: BaseWallet): GenericNetwork
```

#### Parameters

* **wallet** (BaseWallet): The wallet to get network for

#### Returns

* **GenericNetwork**: The current network

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val network = sdk.wallets.getNetwork(wallet)
        println("Network: ${network.name}, Chain ID: ${network.chainId}")
    } catch (e: Exception) {
        println("Failed to get network: ${e.message}")
    }
}
```

### switchNetwork

Switch a wallet to a different network.

```kotlin theme={"system"}
suspend fun switchNetwork(wallet: BaseWallet, network: GenericNetwork)
```

#### Parameters

* **wallet** (BaseWallet): The wallet to switch networks for
* **network** (GenericNetwork): The target network

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val polygon = sdk.networks.evm.first { it.chainId == 137 }
        sdk.wallets.switchNetwork(wallet, polygon)
        println("Switched to ${polygon.name}")
    } catch (e: Exception) {
        println("Failed to switch network: ${e.message}")
    }
}
```

## Message Signing

### signMessage

Sign a message with a wallet.

```kotlin theme={"system"}
suspend fun signMessage(wallet: BaseWallet, message: String): String
```

#### Parameters

* **wallet** (BaseWallet): The wallet to sign with
* **message** (String): The message to sign

#### Returns

* **String**: The signature

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val signature = sdk.wallets.signMessage(wallet, "Hello!")
        println("Signature: $signature")
    } catch (e: Exception) {
        println("Failed to sign: ${e.message}")
    }
}
```

## Typed Data Signing (EIP-712)

### signTypedData

Sign typed data (EIP-712) with a wallet. This is an extension on `sdk.wallets`, so it requires an import.

```kotlin theme={"system"}
import com.dynamic.sdk.android.Chains.EVM.signTypedData

suspend fun signTypedData(wallet: BaseWallet, typedDataJson: String): String
```

#### Parameters

* **wallet** (BaseWallet): The wallet to sign with
* **typedDataJson** (String): The typed data as a JSON string

#### Returns

* **String**: The signature

#### Example

```kotlin theme={"system"}
val typedData = """
{
  "types": {
    "EIP712Domain": [
      {"name": "name", "type": "string"},
      {"name": "chainId", "type": "uint256"}
    ],
    "Person": [
      {"name": "name", "type": "string"}
    ]
  },
  "primaryType": "Person",
  "domain": {
    "name": "My App",
    "chainId": 1
  },
  "message": {
    "name": "Alice"
  }
}
""".trimIndent()

viewModelScope.launch {
    try {
        val signature = sdk.wallets.signTypedData(wallet, typedData)
        println("Signature: $signature")
    } catch (e: Exception) {
        println("Failed to sign: ${e.message}")
    }
}
```

## Signature Verification

The SDK does not expose on-device signature verification. Recover the signer on your backend instead; see the backend verification example in [Message Signing](https://docs.dynamic.xyz/docs/kotlin/wallets/evm/message-signing.md).

## Primary Wallet Management

### setPrimary

Set a wallet as the primary wallet for the user.

```kotlin theme={"system"}
suspend fun setPrimary(walletId: String)
```

#### Parameters

* **walletId** (String): The ID of the wallet to set as primary

#### Example

```kotlin theme={"system"}
viewModelScope.launch {
    try {
        val walletId = wallet.id ?: throw Exception("Wallet ID is null")
        sdk.wallets.setPrimary(walletId)
        println("Set wallet as primary")
    } catch (e: Exception) {
        println("Failed to set primary: ${e.message}")
    }
}
```


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