---
eip: 3085
label: EIP-3085
title: wallet_addEthereumChain RPC Method
status: Stagnant
type: Standards Track
category: Interface
created: 2020-11-01
requires: 155
official: https://eips.ethereum.org/EIPS/eip-3085
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3085.md
canonical: https://eips.huatuo.xyz/zh/eip-3085/
lang: zh
tldr: wallet_addEthereumChain RPC 方法让 dapp 请求钱包添加一条 EVM 链（链 ID、RPC URL、货币、浏览器），由用户批准该请求。
tags: [wallet, json-rpc, multichain, interface, dapp]
---

# EIP-3085: wallet_addEthereumChain RPC Method

> Adds an RPC method to add EVM-compatible chains

**TL;DR:** wallet_addEthereumChain RPC 方法让 dapp 请求钱包添加一条 EVM 链（链 ID、RPC URL、货币、浏览器），由用户批准该请求。

## 它解决什么问题？

部署在 L2 或侧链上的 dapp 需要用户的钱包认识该网络。没有标准时，用户必须手动把链 ID、RPC URL 和货币符号复制到钱包设置中，既容易出错，也容易被钓鱼。

ERC-3085 定义了一个位于 wallet 命名空间的方法，网站可以调用它来*建议*一条链。钱包会验证数据并展示给用户，只有用户批准才会添加该链。

## 它如何运作

`wallet_addEthereumChain` 接受一个对象：

```ts
interface AddEthereumChainParameter {
  chainId: string;              // hex string, e.g. "0xa"
  chainName?: string;
  rpcUrls?: string[];
  nativeCurrency?: { name: string; symbol: string; decimals: number };
  blockExplorerUrls?: string[];
  iconUrls?: string[];
}
```

规范中的关键规则：

- 类型上只有 `chainId` 是必填的，但如果 `rpcUrls` 缺失或为空，或者 `chainId` 与从这些 RPC URL 通过 `eth_chainId` 返回的值不一致，钱包**必须**拒绝该请求。
- URL 必须有效，且不得使用 `http:` 或 `file:`。
- 如果提供了 `nativeCurrency`，则三个字段都是必填的。
- 成功时返回 `null`，否则返回错误。钱包可以出于任何原因拒绝。
- 添加一条链**并不**意味着它会被选中。重新添加一条已存在的链应当成功（除非用户拒绝），并且同一个链 ID 不得被添加两次。

## 示例代码

通过 [EIP-1193](/eip-1193/) provider 添加一条链，然后切换到它：

```ts
const params = {
  chainId: "0xa", // 10
  chainName: "OP Mainnet",
  nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
  rpcUrls: ["https://mainnet.optimism.io"],
  blockExplorerUrls: ["https://optimistic.etherscan.io"],
};

try {
  await window.ethereum.request({ method: "wallet_addEthereumChain", params: [params] });
  // Adding does not select it; ask to switch explicitly (EIP-3326)
  await window.ethereum.request({
    method: "wallet_switchEthereumChain",
    params: [{ chainId: params.chainId }],
  });
} catch (err: any) {
  if (err.code === 4001) console.log("user rejected");
  else throw err;
}
```

## 需要注意

- 状态为 **Stagnant**，不过实际上该方法已被 MetaMask 等浏览器钱包广泛支持。具体行为细节（哪些字段必填、链是否自动选中）在不同钱包之间仍有差异。
- 切换是另一个独立的问题，由 [EIP-3326](/eip-3326/) 的 `wallet_switchEthereumChain` 提出。
- 链 ID 是 [EIP-155](/eip-155/) 的重放保护 ID，格式与 [EIP-695](/eip-695/) 相同。钱包应当使用提交的链 ID 签名，绝不能使用 RPC 端点报告的链 ID。
- 规范中的安全指引：提醒用户 RPC 端点能看到他们的 IP 和活动；将图标视为不可信；优先使用钱包自己已知链的元数据；避免自动批准重复请求而泄露用户已经拥有哪些链。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-3085
