Before this page: have a connected wallet (see Connecting external wallets). Network operations act on a specific WalletAccount that your app supplies.
getActiveNetworkData returns { networkData } for the wallet’s current network — displayName, iconUrl, nativeCurrency, and the networkId. getNetworksData returns every network configured for your project, across all chains — filter it to the wallet’s chain so the picker only offers networks the wallet can actually switch to.
TypeScript
React
import { getActiveNetworkData, getNetworksData, switchActiveNetwork, type WalletAccount,} from '@dynamic-labs-sdk/client';async function renderNetworkPicker( select: HTMLSelectElement, walletAccount: WalletAccount,) { const { networkData } = await getActiveNetworkData({ walletAccount }); // getNetworksData spans every configured chain; a wallet can only switch // within its own chain, so keep only the networks on the wallet's chain. const networks = getNetworksData().filter( (network) => network.chain === walletAccount.chain, ); select.replaceChildren(); for (const network of networks) { const option = document.createElement('option'); option.value = network.networkId; option.textContent = network.displayName; option.selected = network.networkId === networkData?.networkId; select.append(option); } select.addEventListener('change', async () => { await switchActiveNetwork({ networkId: select.value, walletAccount }); });}
import { getNetworksData, type WalletAccount,} from '@dynamic-labs-sdk/client';import { useGetActiveNetworkData, useSwitchActiveNetwork,} from '@dynamic-labs-sdk/react-hooks';function NetworkPicker({ walletAccount }: { walletAccount: WalletAccount }) { const { data } = useGetActiveNetworkData({ walletAccount }); const { mutateAsync: switchNetwork, isPending } = useSwitchActiveNetwork(); // Keep only networks on the wallet's own chain — the only ones it can switch to. const networks = getNetworksData().filter( (network) => network.chain === walletAccount.chain, ); return ( <select value={data?.networkData?.networkId ?? ''} disabled={isPending} onChange={(event) => switchNetwork({ networkId: event.target.value, walletAccount }) } > {networks.map((network) => ( <option key={network.networkId} value={network.networkId}> {network.displayName} </option> ))} </select> );}
The active-network query refetches on networkChanged, so the picker reflects switches made anywhere — including from inside the wallet.
Before a transaction that must run on a specific network, check the active network and switch if needed. Some wallets don’t allow programmatic switching — isProgrammaticNetworkSwitchAvailable tells you whether to switch for the user or ask them to switch in their wallet.
TypeScript
React
import { getActiveNetworkData, switchActiveNetwork, isProgrammaticNetworkSwitchAvailable,} from '@dynamic-labs-sdk/client';import type { WalletAccount } from '@dynamic-labs-sdk/client';// Ensure the wallet is on `requiredNetworkId`; returns whether it's safe to proceed.async function ensureNetwork( walletAccount: WalletAccount, requiredNetworkId: string,): Promise<boolean> { const { networkData } = await getActiveNetworkData({ walletAccount }); if (networkData?.networkId === requiredNetworkId) return true; if (isProgrammaticNetworkSwitchAvailable({ walletAccount })) { await switchActiveNetwork({ networkId: requiredNetworkId, walletAccount }); return true; } // promptManualSwitch is your implementation — tell the user to switch in their wallet. promptManualSwitch(requiredNetworkId); return false;}
Call your network check right before sending — not just on page load. A user can switch networks in their wallet at any time, so validate at the moment the network actually matters.