主页EIPs
EIPsEIP-2015
EIP-2015

wallet_updateEthereumChain RPC Method

Adds an RPC method to switch between EVM-compatible chains
StagnantStandards Track: Interface
创建时间: 2019-05-12
关联 EIP: EIP-155
Pedro Gomes (@pedrouid), Erik Marks (@rekmarks), Pandapip1 (@Pandapip1)
社区讨论原文链接编辑
1 分钟了解
欢迎补充好内容
去提交
相关视频
欢迎补充好内容
去提交
正文

Abstract

This EIP adds a wallet-namespaced RPC endpoint, wallet_updateEthereumChain, providing a standard interface for switching chains. The method takes the minimal parameters of chainId, chainName, rpcUrl, nativeCurrency and blockExplorerUrl.

Specification

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

This proposal adds a method to a wallet's web3 provider API: wallet_updateEthereumChain.

wallet_updateEthereumChain

The wallet_updateEthereumChain method is used to switch to a network, and registering it with the wallet if it isn't already recognized.

The wallet_updateEthereumChain method takes one parameter, an EthereumChainSwitchRequest object, defined below:

interface NativeCurrencyData { name: string; symbol: string; decimals: number; } interface EthereumChainSwitchRequest { chainId: string; chainName?: string; rpcUrls?: string[]; nativeCurrency?: NativeCurrencyData; blockExplorerUrl?: string; }

The chainId is the 0x-prefixed EIP-155-compliant chain ID. The chainName is a suggested human-readable name of the chain, to be displayed to the user. The rpcUrls array is a list of RPC endpoints for the given chainId. The nativeCurrency object suggests how the native currency should be displayed. Its parameters, name, symbol, and decimals, should be interpreted like in ERC-20. Finally, the blockExplorerUrl should link to a block explorer compatible with the given chainId.

All keys other than the chainId are optional. All keys other than chainId are suggestions to the wallet. Wallets can choose to ignore or display other data to users. Wallets should prompt the user before switching or adding chains. Wallets should also store a default list of data for commonly-used chains, in order to avoid phishing attacks. Wallets MUST sanitize each RPC url before using it to send other requests, including ensuring that it responds correctly to the net_version and eth_chainId methods.

The wallet_updateEthereumChain method returns true if the active chain matches the requested chain, regardless of whether the chain was already active or was added to the wallet previously. If the user rejects the request, it must return an error with code 4001.

Rationale

The wallet_updateEthereumChain method is designed to be as simple as possible, while still providing the necessary information for a wallet to switch to a new chain. The chainId is the only required parameter, as it is the only parameter that is guaranteed to be unique. The chainName is included to provide a human-readable name for the chain, and the rpcUrls array is included to provide a list of RPC endpoints for the chain. The nativeCurrency object is included to provide a suggestion for how the native currency should be displayed. Finally, the blockExplorerUrl is included to provide a link to a block explorer for the chain.

The wallet_updateEthereumChain method is namespaced under wallet_ to avoid conflicts with other methods. The wallet_ prefix is used by other methods that are wallet-specific, such as wallet_addEthereumChain and wallet_switchEthereumChain.

Backwards Compatibility

This EIP is fully backwards compatible.

Security Considerations

Server-Side Request Forgery (SSRF)

The rpcUrls parameter is a list of RPC endpoints for the chain. Wallets should sanitize each RPC url before using it to send other requests, including ensuring that it responds correctly to the net_version and eth_chainId methods.

Phishing

Wallets should store a default list of data for commonly-used chains, in order to avoid phishing attacks.

Copyright and related rights waived via CC0.

扩展阅读
欢迎补充好内容
去提交
相关项目
欢迎补充好内容
去提交

不想错过最新的 EIP 动态?

订阅 EIPs Fun 周刊以跟进相关更新,建⽴你与 EIP 之间的连接 ,更好地建设以太坊。

详情
支持以太坊贡献者,推动生态建设
资源
GitHub
支持社区