Hook for getting metadata about the network the current wallet is connected to and switching networks
Example
import { useNetwork } from"@thirdweb-dev/react";
constApp = () => { const [, switchNetwork] = useNetwork(); return ( // switchNetwork is undefined if the wallet does not support programmatic network switching // 137 is the chainId for Polygon in this example <buttononClick={() =>switchNetwork(137)}> Switch Network </button> ); };
It's important to note that some wallet apps do not support programmatic network switching and switchNetwork will be undefined.
For those situations, you can typically switch networks in the wallet app this hook will still work.
Deprecated
useChain
,useSwitchChain
,useChainId
insteadHook for getting metadata about the network the current wallet is connected to and switching networks
Example
It's important to note that some wallet apps do not support programmatic network switching and switchNetwork will be undefined. For those situations, you can typically switch networks in the wallet app this hook will still work.