useSwitchChain
Hook to switch blockchain networks with Embedded Wallets.
Import
import { useSwitchChain } from '@web3auth/modal/react'
Usage
import { useSwitchChain } from '@web3auth/modal/react'
function SwitchChainButton() {
const { switchChain, loading, error } = useSwitchChain()
return (
<div>
<button onClick={() => switchChain('0x1')} disabled={loading}>
{loading ? 'Switching...' : 'Switch to Ethereum Mainnet'}
</button>
{error && <span>Error: {error.message}</span>}
</div>
)
}
Return type
import { type IUseSwitchChain } from '@web3auth/modal/react'