> ## 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 title="Recommended: JavaScript SDK with React Hooks" icon="react" color="#4779FE">
  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)](/javascript/reference/react-quickstart) to get started.
</Card>

## 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](/react/reference/objects/evmNetwork#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](/react/reference/hooks/usedynamiccontext),
you have two useful methods for network switching:

<ParamField path="supportsNetworkSwitching" type="() => boolean">
  Available on the connector object for the wallet.Whether the connector supports network switching.
</ParamField>

<ParamField path="switchNetwork" type="(networkChainId?: number | string) => Promise<void>">
  Available directly on the wallet object. Switch to another network by providing either the network name or chain id.
</ParamField>

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');
}
```

<Frame>
  <img src="https://mintcdn.com/dynamic-docs/S0I4gBjjMnJYbuz8/images/widget/widget-network-switching.png?fit=max&auto=format&n=S0I4gBjjMnJYbuz8&q=85&s=b908f9cefefc8ce98f63891a011e7636" alt="1440" width="1440" height="732" data-path="images/widget/widget-network-switching.png" />
</Frame>
