# useSwitchChain

> @web3auth/modal React Hooks useSwitchChain | Embedded Wallets

Hook to switch blockchain networks with Embedded Wallets.

### Import

```tsx

```

### Usage

```tsx

function SwitchChainButton() {
  const { switchChain, loading, error } = useSwitchChain()

  return (
    
      <button onClick={() => switchChain('0x1')} disabled={loading}>
        {loading ? 'Switching...' : 'Switch to Ethereum Mainnet'}
      </button>
      {error && Error: {error.message}}
    
  )
}
```

### Return type

```tsx

```

#### `loading`

`boolean`

Whether the chain switching process is in progress.

#### `error`

`Web3AuthError | null`

Error that occurred during the chain switching process.

#### `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

```tsx title="switchChain.tsx"

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

  const { switchChain, error } = useSwitchChain()

  return (
    
      Switch chain
      Connected to {web3Auth?.currentChain?.displayName}
      {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}
    
  )
}
```
