useSwitchChain

Hook for switching to a different network.

Example

import { useSwitchChain } from "@thirdweb-dev/react";
import { Goerli } from "@thirdweb-dev/chains";
function App() {
const switchChain = useSwitchChain();
return (
<button onClick={() => switchChain(Goerli.chainId)}>
Switch to Goerli
</button>
);
}
function useSwitchChain(): (chain: number) => Promise<void>;

Returns

let returnType: (chain: number) => Promise<void>;

A function to switch the network in the currently connected wallet to network with given chainId