EIP-2015 Wallet chain-switching RPC method (wallet_updateEthereumChain RPC Method)
No call decision · Networking & nodes · EIP status Stagnant · created 2019-05-12
Adds an RPC method called wallet_updateEthereumChain to wallets, allowing an app to request, in a standardized way, that the wallet switch to a different chain based on chainId.
Why it is needed
Until now, there was no standard way for an app to request that a wallet switch to a different chain. Each app conveyed network information to the wallet in its own way, and if a wallet did not validate the RPC address or chain information it received, this created risks such as phishing, where a user ends up connected to a fake network, or SSRF (server-side request forgery), where the wallet ends up sending requests to a malicious server. EIP-2015 standardizes a wallet_updateEthereumChain method that requests a chain switch based on chainId, allowing wallets to consistently perform user approval procedures and RPC address validation.
What changes
Today
- No standard RPC method exists for an app to request a chain switch
- Each wallet handles adding and switching networks differently
- Using an RPC address without validation risks phishing and SSRF
After EIP-2015
- Standardizing chain-switch requests via wallet_updateEthereumChain
- Only chainId is required; chainName, rpcUrls, and others are optional suggested values
- The wallet validates the RPC address using net_version and eth_chainId
- If the user rejects, error code 4001 is returned
Who is affected
- Users: Because the wallet requests approval before switching chains, phishing risk is reduced.
- dApp developers: A single method under the wallet_ namespace allows the same chain-switch request to be made consistently across different wallets.
- Wallet developers: They are responsible for RPC address validation, the user approval procedure, and maintaining a default list of commonly used chains.
In depth
Method parameters
wallet_updateEthereumChain takes a single EthereumChainSwitchRequest object. chainId is an EIP-155-style chain ID starting with 0x and is the only required value. The remaining fields, chainName (a human-readable name), rpcUrls (a list of RPC endpoints), nativeCurrency (native token display information consisting of name, symbol, and decimals), and blockExplorerUrl (a block explorer link), are all optional and merely suggestions to the wallet, which may ignore them or display them differently.
Return value and rejection handling
The method returns true if the requested chain matches the currently active chain. This holds regardless of whether the chain was already active or was newly added and switched to. If the user rejects the request, the wallet MUST return error code 4001.
The wallet's validation and approval obligations
A wallet should prompt the user before switching to or adding a chain. It must also validate each RPC url before actually using it, which includes confirming that it responds correctly to the net_version and eth_chainId methods.
A default chain list to prevent phishing
Wallets are recommended to store information for commonly used chains as default values. This is because if a wallet blindly trusts suggested values sent by an app, such as chainName or blockExplorerUrl, a user could be deceived by a fake name or a fake explorer link.
SSRF risk and RPC url validation
rpcUrls is a list of RPC endpoints for the given chainId. If a wallet uses these addresses to send requests without validation, it can lead to server-side request forgery (SSRF), so the original text specifies that each RPC url must be sanitized before use and that the net_version and eth_chainId responses must be checked.
Relationship to the namespace and other methods
This method is defined under the wallet_ namespace so that its name does not collide with other wallet-specific methods. The original text cites wallet_addEthereumChain and wallet_switchEthereumChain as examples that use the same namespace.
Current status
This EIP's status is Stagnant, meaning it is not currently an actively progressing proposal. It lists EIP-155 under requires as the basis for the chainId format.