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

# Adding a network

<Note>
  This function was introduced in SDK version **0.4.0**.
</Note>

Use `addNetwork` to add a network to a wallet provider. This function requests that the wallet provider add a network to its list of available networks.

## Usage

```javascript theme={"system"}
import { addNetwork, NetworkAddingUnavailableError } from '@dynamic-labs-sdk/client';

const addNetworkToWallet = async () => {
  try {
    await addNetwork({ 
      walletAccount, 
      networkData: {
        chainId: 137,
        chainName: 'Polygon',
        nativeCurrency: {
          name: 'MATIC',
          symbol: 'MATIC',
          decimals: 18
        },
        rpcUrls: ['https://polygon-rpc.com'],
        blockExplorerUrls: ['https://polygonscan.com']
      }
    });
  } catch (error) {
    if (error instanceof NetworkAddingUnavailableError) {
      console.error('This wallet does not support adding networks');
    }
  }
}
```

## React

```tsx theme={"system"}
import { addNetwork, NetworkAddingUnavailableError } from '@dynamic-labs-sdk/client';
import { useGetWalletAccounts } from '@dynamic-labs-sdk/react-hooks';

function AddPolygonButton() {
  const { data: walletAccounts = [] } = useGetWalletAccounts();
  const walletAccount = walletAccounts[0];

  const handleAdd = async () => {
    if (!walletAccount) return;
    try {
      await addNetwork({
        walletAccount,
        networkData: {
          chainId: 137,
          chainName: 'Polygon',
          nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 },
          rpcUrls: ['https://polygon-rpc.com'],
          blockExplorerUrls: ['https://polygonscan.com'],
        },
      });
    } catch (error) {
      if (error instanceof NetworkAddingUnavailableError) {
        console.error('This wallet does not support adding networks');
      }
    }
  };

  return (
    <button onClick={handleAdd} disabled={!walletAccount}>
      Add Polygon
    </button>
  );
}
```

## Parameters

* `walletAccount` - The wallet account to add the network for.
* `networkData` - The network configuration data to add to the wallet.
* `client` (optional) - The Dynamic client instance. Only required when using multiple Dynamic clients.

## Error Handling

The `addNetwork` function can throw the following errors:

### NetworkAddingUnavailableError

If the wallet provider does not support adding networks, the function will throw a `NetworkAddingUnavailableError` error. In this case, the user must manually add the network in their wallet.

## Related functions

* [Switching Active Network](/javascript/reference/wallets/switch-active-network)
* [Getting Active Network](/javascript/reference/wallets/get-active-network)
* [Getting Networks Data](/javascript/reference/wallets/get-networks-data)
