Chains/Networks
Switching Networks
Usage
Using the WalletConnector instance provided by useDynamicContext, you have two useful methods for network switching
Method | Description |
---|---|
supportsNetworkSwitching(): boolean | whether the connector supports network switching. |
switchNetwork({ networkChainId, networkName }: { networkChainId?: number; networkName?: string; }): Promise<void> | switch to another network by provider either the network name or chain id specified in the list of EvmNetwork |
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
const { walletConnector } = useDynamicContext();
if (walletConnector.supportsNetworkSwitching()) {
await walletConnector.switchNetwork({ networkChainId: 137 });
console.log("Success! Network switched");
}
Was this page helpful?