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

# Using Networks

> [card] Recommended: JavaScript SDK with React Hooks
>
> For new React apps, we recommend the JavaScript SDK with React Hooks (`@dynamic-labs-sdk/react-hooks`) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the [React quickstart (JavaScript SDK)](https://docs.dynamic.xyz/docs/javascript/reference/react-quickstart.md) to get started.

## Fetching Enabled Networks

The wallet connector provides the `getEnabledNetworks` method:

```tsx React theme={"system"}
const enabledNetworks = primaryWallet.connector.getEnabledNetworks();
```

This method returns an array of [network objects](https://docs.dynamic.xyz/docs/react/reference/objects/evmNetwork.md#evmnetwork).

## Example

```tsx React theme={"system"}
const { primaryWallet } = useDynamicContext();

if(!primaryWallet) return;

const enabledNetworks = primaryWallet.connector.getEnabledNetworks();

return (
  <div>
    {enabledNetworks.map((network) => (
      <div key={network.chainId}>{network.chainName}</div>
    ))}
  </div>
)
```

### Network Switching

### Usage

Using the primaryWallet provided by [useDynamicContext](https://docs.dynamic.xyz/docs/react/reference/hooks/usedynamiccontext.md),
you have two useful methods for network switching:

**supportsNetworkSwitching** `() =\> boolean`

Available on the connector object for the wallet.Whether the connector supports network switching.

**switchNetwork** `(networkChainId?: number | string) =\> Promise\<void\>`

Available directly on the wallet object. Switch to another network by providing either the network name or chain id.

When calling `switchNetwork` with a connector supporting network switching, the SDK will either request the user to confirm the network switch or add the network if it was not previously set.

### Example

```typescript theme={"system"}
const { primaryWallet } = useDynamicContext();

if (primaryWallet?.connector.supportsNetworkSwitching()) {
  await primaryWallet.switchNetwork(137);
  console.log('Success! Network switched');
}
```

![1440](https://mintcdn.com/dynamic-docs/S0I4gBjjMnJYbuz8/images/widget/widget-network-switching.png?fit=max\&auto=format\&n=S0I4gBjjMnJYbuz8\&q=85\&s=b908f9cefefc8ce98f63891a011e7636)


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