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

# Network Management

Switch between blockchain networks and query the current network.

## Get Current Network

Retrieve the current network for a wallet:

```kotlin theme={"system"}
import com.dynamic.sdk.android.DynamicSDK
import com.dynamic.sdk.android.Models.BaseWallet

val sdk = DynamicSDK.getInstance()
val wallet: BaseWallet = sdk.wallets.userWallets.first()

val network = sdk.wallets.getNetwork(wallet)
println("Current network: $network")
println("Chain ID: ${network.chainId}")
```

## Switch Network

Switch a wallet to a different network:

```kotlin theme={"system"}
import com.dynamic.sdk.android.DynamicSDK
import com.dynamic.sdk.android.Models.BaseWallet
import com.dynamic.sdk.android.Models.Network
import kotlinx.serialization.json.JsonPrimitive

val sdk = DynamicSDK.getInstance()
val wallet: BaseWallet = sdk.wallets.userWallets.first { it.chain == "EVM" }

// Switch to Polygon (chain ID 137)
val polygonNetwork = Network(JsonPrimitive(137))
sdk.wallets.switchNetwork(wallet, polygonNetwork)

// Switch to Ethereum Mainnet (chain ID 1)
val mainnetNetwork = Network(JsonPrimitive(1))
sdk.wallets.switchNetwork(wallet, mainnetNetwork)

// Switch to Base (chain ID 8453)
val baseNetwork = Network(JsonPrimitive(8453))
sdk.wallets.switchNetwork(wallet, baseNetwork)
```

## Common Network IDs

Here are some commonly used network chain IDs:

### Ethereum Networks

| Network          | Chain ID |
| ---------------- | -------- |
| Ethereum Mainnet | 1        |
| Sepolia Testnet  | 11155111 |
| Holesky Testnet  | 17000    |

### Layer 2 Networks

| Network                  | Chain ID |
| ------------------------ | -------- |
| Polygon                  | 137      |
| Polygon Mumbai (Testnet) | 80001    |
| Arbitrum One             | 42161    |
| Arbitrum Sepolia         | 421614   |
| Optimism                 | 10       |
| Optimism Sepolia         | 11155420 |
| Base                     | 8453     |
| Base Sepolia             | 84532    |

## Best Practices

### 1. Handle Network Switching Gracefully

Always handle errors and provide feedback to users:

```kotlin theme={"system"}
try {
    sdk.wallets.switchNetwork(wallet, network)
} catch (e: Exception) {
    when {
        e.message?.contains("user rejected") == true -> {
            showMessage("Network switch cancelled")
        }
        e.message?.contains("unsupported") == true -> {
            showMessage("This network is not supported")
        }
        else -> {
            showMessage("Failed to switch network: ${e.message}")
        }
    }
}
```

### 2. Verify Network After Switching

Confirm the network switch was successful:

```kotlin theme={"system"}
val network = Network(JsonPrimitive(chainId))
sdk.wallets.switchNetwork(wallet, network)

// Verify the switch
val currentNetwork = sdk.wallets.getNetwork(wallet)
if (currentNetwork.chainId == chainId.toString()) {
    println("Successfully switched to chain $chainId")
}
```

### 3. Support Testnet Networks

Make it easy for developers to test:

```kotlin theme={"system"}
val isTestnet = when (chainId) {
    11155111, 80001, 421614, 11155420, 84532 -> true
    else -> false
}

if (isTestnet) {
    showWarning("You are connected to a testnet")
}
```

## Troubleshooting

### Network Switch Fails

* Verify the chain ID is correct
* Check that the network is enabled in your Dynamic dashboard
* Ensure the wallet type supports the network (EVM wallets only)

### Wrong Network Displayed

* Call `getNetwork()` after switching to verify
* Check for any pending transactions on the old network

## What's Next

* [Token Balances](/kotlin/wallets/general/token-balances) - Check wallet balances
* [Send Transactions](/kotlin/wallets/evm/send-eth) - Send transactions on different networks
* [Smart Contracts](/kotlin/wallets/evm/smart-contracts) - Learn more about EVM operations
