Core Hooks
useSwitchNetwork
Was this page helpful?
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
🚀 Stablecoin Accounts are live! Learn more
| Method | Type | Description |
|---|---|---|
| switchNetwork | (args: { wallet: Wallet; network: number | string }) => Promise<void> | Function to switch the given wallet to the given network id |
import React from "react";
import {
useSwitchNetwork,
useDynamicContext,
} from "@dynamic-labs/sdk-react-core";
import { base } from "viem/chains";
const NetworkSwitcher = () => {
const switchNetwork = useSwitchNetwork();
const { primaryWallet } = useDynamicContext();
return (
<>
<button
onClick={() =>
switchNetwork({ wallet: primaryWallet, network: base.id })
}
>
Switch to Base
</button>
</>
);
};
Was this page helpful?