Switching or adding alternative EVM-compatible chains
Coinbase Wallet SDK and Coinbase Wallet clients support both EIP-3326wallet_switchEthereumChain
and EIP-3085 wallet_addEthereumChain
requests for switching networks.
For apps supporting multiple networks, Coinbase Wallet SDK only needs 1 rpcUrl — the rpcUrl of the chain the app wishes to default users to.
If Wallet SDK receives either a wallet_switchEthereumChain
or wallet_addEthereumChain
request for a whitelisted network then it switches the user to that network after asking approval from the user.
Coinbase Wallet clients handle wallet_addEthereumChain
requests for non-whitelisted networks (for example, a network such as Harmony One
which is not currently supported by clients by default).
An app can determine if a network is whitelisted or not by sending a wallet_switchEthereumChain
request for that network. If error code 4092 is returned, then the network is not supported by default by the client wallet.
Example
Here’s how to request the wallet switch networks:wallet_switchEthereumChain
, determine if the network is supported by the wallet based on the error code, and follow with a wallet_addEthereumChain
request if the network is not supported. Here’s an example: