EIP-2015: Wallet Update Ethereum Chain RPC Method (`wallet_updateEthereumChain`)
作者 | Pedro Gomes, Erik Marks |
---|---|
讨论-To | https://ethereum-magicians.org/t/eip-2015-wallet-update-chain-json-rpc-method-wallet-updatechain/3274 |
状态 | Stagnant |
类型 | Standards Track |
分类 | Interface |
创建日期 | 2019-05-12 |
依赖 | 155, 1474 |
英文版 | https://eips.ethereum.org/EIPS/eip-2015 |
简述
Wallets can update the active chain when connected to a Dapp but not vice-versa, with wallet_updateEthereumChain
the Dapp will be able to request this change from the Wallet.
摘要
Dapp can request the Wallet to switch chains by providing the minimal parameters of chainId
, chainName
, rpcUrl
, nativeCurrency
and blockExplorerUrl
. The Wallet will display a UI element to inform the user of this change.
动机
Wallet and Dapp communication rely on the present provider that acts as middleware between the two. Using JSON-RPC methods, the Dapp is able to access not only the active accounts but also the active chain. With EIP-1102 we introduced the ability for Dapps to request access to the active accounts and the Wallet is able to provide a simple UI to inform the user of this action however the same is not currently possible for switching chains. The current pattern is to display some UI to request the user to switch chains within the Dapp, however this could be easily improved by triggering a UI from the Wallet side that can be approved or rejected by the user instead.
规范
The JSON RPC method will be part of wallet_
namespaced methods which aim to improve the UX and interoperability between Dapps and Wallets.
Required Parameters
- chainId (string): the id of the chain compliant with EIP-155
- chainName (string): the name of the chain to update
- rpcUrl (string): the url endpoint for RPC requests for this chain
- nativeCurrency (Object): includes three fields for
name
(string),symbol
(string) anddecimals
(number) - blockExplorerUrl (string): the url endpoint for a block explorer web site for the chain.
Best Practices
- The Wallet should display a UI view similar to a EIP-1102 informing the user that the currently connected Dapp wants to switch to the specified chain.
- the Wallet should default the rpcUrl to any existing endpoints matching a chainId known previously to the wallet, otherwise it will use the provided rpcUrl as a fallback.
- the Wallet should call the rpcUrl with
net_version
andeth_chainId
to verify the provided chainId and networkId match the responses from the rpcUrl - the Wallet should change all nativeCurrency symbols to the provided parameter
Example 1
A JSON-RPC request from a Dapp to switch the Ethereum Goerli chain would be as follows:
{
"id":1,
"jsonrpc": "2.0",
"method": "wallet_updateChain",
"params": [
{
"chainId": 0x5,
"chainName": "Goerli",
"rpcUrl": "https://goerli.infura.io/v3/406405f9c65348f99d0d5c27104b2213",
"nativeCurrency": {
"name": "Goerli ETH",
"symbol": "gorETH"
},
"blockExplorerUrl": "https://goerli.etherscan.io"
}
]
}
Example 2
A JSON-RPC request from a Dapp to switch the POA Network’s xDAI chain would be as follows:
{
"id":1,
"jsonrpc": "2.0",
"method": "wallet_updateChain",
"params": [
{
"chainId": "0x5",
"chainName": "Goerli",
"rpcUrl": "https://goerli.infura.io/v3/406405f9c65348f99d0d5c27104b2213",
"nativeCurrency": {
"name": "Goerli ETH",
"symbol": "gorETH"
},
"blockExplorerUrl": "https://goerli.etherscan.io"
}
]
}
Responses
A success response:
{
"id": 1,
"jsonrpc": "2.0",
"result": true
}
A failure response:
{
"id": 1,
"jsonrpc": "2.0",
"error": {
"code": 4001,
"message": "The user rejected the request."
}
}
版权声明
Copyright and related rights waived via CC0.
参考文献
Please cite this document as:
Pedro Gomes, Erik Marks, "EIP-2015: Wallet Update Ethereum Chain RPC Method (`wallet_updateEthereumChain`) [DRAFT]," Ethereum Improvement Proposals, no. 2015, May 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2015.