Switch chains
To switch the network of a connected wallet, first find the corresponding ConnectedWallet
object from the wallets
array.
Then, call the wallet’s switchChain
method. As a parameter to the method, pass the chain ID for your desired network as a number
or hexadecimal string
:
For embedded wallets, switchChain
will update the network of the embedded wallet behind the scenes. For external wallets, switchChain
will prompt the user to switch to the target network within the external wallet’s client (e.g. their browser extension or mobile app).
switchChain
returns a Promise that resolves to void
once the wallet has successfully been switched to the target network. The Promise will reject with an error if:
- The target chain has not been configured.
- The user declines the request to switch their network, if using an external wallet.
To switch the network of a connected wallet, first find the corresponding ConnectedWallet
object from the wallets
array.
Then, call the wallet’s switchChain
method. As a parameter to the method, pass the chain ID for your desired network as a number
or hexadecimal string
:
For embedded wallets, switchChain
will update the network of the embedded wallet behind the scenes. For external wallets, switchChain
will prompt the user to switch to the target network within the external wallet’s client (e.g. their browser extension or mobile app).
switchChain
returns a Promise that resolves to void
once the wallet has successfully been switched to the target network. The Promise will reject with an error if:
- The target chain has not been configured.
- The user declines the request to switch their network, if using an external wallet.
By default, embedded wallets will be connected to the first network specified in your supportedChains
array, and to Ethereum mainnet if no supportedChains
are specified.
To switch the embedded wallet to a different network, send a wallet_switchEthereumChain
JSON-RPC request to the wallet’s EIP-1193 provider. In the request’s params
, specify your target chainId
as a hexadecimal string.
You can also use the eth_chainId
request (with no params
) to get the current network of the embedded wallet.