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

# switchChain

Function to switch blockchain networks with Web3Auth.

## Usage[​](#usage "Direct link to Usage")

```
await web3auth.switchChain({ chainId: '0xaa36a7' })

```

## Parameters[​](#parameters "Direct link to Parameters")

- Table
- Function Definition

| Parameter           | Description                                                              | Type   | Required |
| ------------------- | ------------------------------------------------------------------------ | ------ | -------- |
| { chainId: string } | Chain ID of the chain to switch to, for example, { chainId: "0xaa36a7" } | Object | Yes      |

```
async switchChain(params: { chainId: string }): Promise<void> {
    if (this.status !== ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw WalletLoginError.notConnectedError(`No wallet is connected`);
    return this.walletAdapters[this.connectedAdapterName].switchChain(params);
}

```

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

switchChain.js

```
// Initialize Web3Auth first
// ...

// Switch to Sepolia Testnet
try {
  await web3auth.switchChain({ chainId: '0xaa36a7' })
  console.log('Successfully switched to Sepolia Testnet')
} catch (error) {
  console.error('Error switching chain:', error)
}

// Later, switch to Ethereum Mainnet
try {
  await web3auth.switchChain({ chainId: '0x1' })
  console.log('Successfully switched to Ethereum Mainnet')
} catch (error) {
  console.error('Error switching chain:', error)
}

```
