Ethereum Chain Calls: Switch First, Add on 4902
For wallet_switchEthereumChain vs wallet_addEthereumChain, call switch first; add the Chainlist network parameters only when the wallet returns error 4902.
The EthNews Desk4 min read

Call wallet_switchEthereumChain first; if the connected wallet reports error 4902 for an unknown chain, call wallet_addEthereumChain with that network’s parameters. This is the reliable order for a dapp connect flow because users who already have the network can switch without an unnecessary add prompt.
Before the calls, have an EIP-1193 provider and the target network’s configuration ready. To find the Chain ID, RPC endpoints, native currency, and related details for an EVM network, go further with Chainlist.
Which call should come first?
wallet_switchEthereumChain should come first because it asks the wallet to select a network it may already know. It is the method specified by EIP-3326. wallet_addEthereumChain, specified by EIP-3085, asks the wallet to add network details; it is not a substitute for trying to switch first.
Start with the dapp connected to the wallet on the wrong chain. Choose the target network and gather its configuration from Chainlist: its Chain ID, chain name, RPC URL, native currency, and block explorer URL. The wallet needs the target Chain ID for the switch request. If it already recognizes that chain, the switch request can complete without asking the user to add it.
Convert the target Chain ID to a 0x-prefixed hexadecimal string with no leading zeros. For Polygon, the decimal Chain ID is 137 and its hexadecimal form is 0x89. Send wallet_switchEthereumChain with { chainId: '0x89' }. Resolve the operation if the request succeeds; the network is then selected in the wallet.
Use the hexadecimal representation consistently in both wallet calls. Passing decimal 137 instead of the string '0x89' can make both requests fail because these methods expect the chain ID in hexadecimal form. A correctly formatted ID matters even when the network parameters are otherwise complete.
Catch a failed switch and inspect its error code. If the wallet returns 4902, it does not recognize the target chain, so call wallet_addEthereumChain with the complete configuration: chainId, chainName, rpcUrls, nativeCurrency, and blockExplorerUrls. Use the values for the same network you selected; the add request gives the wallet the information it needs to offer that chain.
Stop if the error is 4001: that code means the user rejected the request. Do not retry the switch or add call automatically. Some mobile wallets used through WalletConnect wrap the 4902 code inside data.originalError.code, so check both the top-level error code and that nested code before deciding whether to add.
After adding the chain successfully, call wallet_switchEthereumChain again with the same hexadecimal Chain ID if the wallet has not switched as part of its handling of the add request. Then listen for chainChanged and refresh the dapp’s chain-dependent state. Treat that event as the signal to update what the interface shows, rather than assuming that a completed add request means the app is already on the target network.
Confirm completion by reading eth_chainId from the provider. The wallet should show the target network, and the returned value should match the target hexadecimal ID, such as 0x89 for Polygon. The connect flow is ready when both the wallet selection and the provider’s chain ID agree.
Why does wallet_addEthereumChain not switch the network?
wallet_addEthereumChain submits network parameters for the wallet to add; the dapp should not treat that request as proof that the wallet is now connected to that chain. That is why the flow tries EIP-3326’s switch method first, then uses EIP-3085’s add method only for an unknown-chain error, and switches again if needed. The dapp should update its state after observing the selected Chain ID.
Related
How do I detect the current chain ID in a dapp?
Call eth_chainId on the EIP-1193 provider to read the wallet’s current Chain ID. Compare that hexadecimal value with the target ID, and subscribe to chainChanged so the dapp can refresh when the user changes networks.
Why does wallet_addEthereumChain not switch the network?
The add request supplies network details for the wallet; use wallet_switchEthereumChain to request selection of that network. In the connect flow, try the switch first, add only after 4902, and verify the resulting Chain ID through the provider.