> For the complete documentation index, see [llms.txt](/llms.txt).

# useSwitchChain

Hook to switch blockchain networks with Embedded Wallets.

### Import[​](#import "Direct link to Import")

```
import { useSwitchChain } from '@web3auth/modal/react'

```

### Usage[​](#usage "Direct link to 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[​](#return-type "Direct link to Return type")

```
import { type IUseSwitchChain } from '@web3auth/modal/react'

```

#### `loading`[​](#loading "Direct link to loading")

`boolean`

Whether the chain switching process is in progress.

#### `error`[​](#error "Direct link to error")

`Web3AuthError | null`

Error that occurred during the chain switching process.

#### `switchChain`[​](#switchchain "Direct link to switchchain")

`(chainId: string) => Promise<void>`

Function to initiate the chain switch. Pass the target `chainId` as a string (for example, "0x1" for Ethereum Mainnet).

## Example[​](#example "Direct link to Example")

switchChain.tsx

```
import { useSwitchChain, useWeb3Auth } from '@web3auth/modal/react'

export function SwitchChain() {
  const { web3Auth } = useWeb3Auth()

  const { switchChain, error } = useSwitchChain()

  return (
    <div>
      <h2>Switch chain</h2>
      <h3>Connected to {web3Auth?.currentChain?.displayName}</h3>
      {web3Auth?.coreOptions.chains?.map(chain => {
        return (
          <button
            disabled={web3Auth?.currentChain?.chainId === chain.chainId}
            key={chain.chainId}
            onClick={() => switchChain(chain.chainId)}
            type="button"
            className="card">
            {chain.displayName}
          </button>
        )
      })}

      {error?.message}
    </div>
  )
}

```
