---
eip: 3770
label: ERC-3770
title: Chain-specific addresses
status: Draft
type: Standards Track
category: ERC
created: 2021-08-26
official: https://eips.ethereum.org/EIPS/eip-3770
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-3770.md
canonical: https://eips.huatuo.xyz/zh/eip-3770/
lang: zh
tldr: "在地址前加上人类可读的链简称前缀，如 `eth:0x…`，让钱包和用户能分辨一个地址属于哪个网络。"
tags: [address, multichain, wallet, ux]
---

# ERC-3770: Chain-specific addresses

> Prepending chain-specific addresses with a human-readable chain identifier

**TL;DR:** 在地址前加上人类可读的链简称前缀，如 `eth:0x…`，让钱包和用户能分辨一个地址属于哪个网络。

## 它解决什么问题？

每条 EVM 链都使用相同的 20 字节地址格式。以太坊主网上的 `0xAbC…` 和某个 L2 或侧链上的 `0xAbC…` 看起来完全一样，但它们可能是截然不同的东西：在一条链上是 EOA，在另一条链上是合约，或者什么都不是。丢失资金的一个经典原因，就是把代币发送到某个智能合约钱包地址，而该钱包在这条链上从未被部署。

[EIP-155](/eip-155/) 的链 ID 已经能识别网络，但它是为开发者和签名设计的数字，不是人们一眼就能认出的东西。ERC-3770 给地址加上一个简短、可读的链标签，随地址本身一起传递。

## 它如何运作

链专属地址就是：

```
shortName:address
```

- `shortName` 是必需的，必须是 `github.com/ethereum-lists/chains` 社区注册表中的有效链简称（也就是把简称映射到链 ID 的同一份列表）。
- `address` 是必需的，必须是符合 [EIP-55](/eip-55/) 校验和的十六进制地址。
- 两部分之间用一个冒号分隔。

这就是全部规范。看到带前缀地址的钱包或 dApp，会在注册表中查找该简称，将其解析为链 ID，然后在地址被用在错误的链上时警告用户（或切换网络）。以这种方式显示地址，也让复制粘贴的地址具备自描述性。

## 示例代码

用 TypeScript（ethers v6）解析并验证链专属地址。这里的简称表只是一个很小的示意子集；真实应用应加载 ethereum-lists 注册表。

```ts
import { getAddress } from "ethers";

// Illustrative subset; load the full registry in production.
const SHORT_NAMES: Record<string, number> = {
  eth: 1,
  oeth: 10,
  arb1: 42161,
};

export function parseChainAddress(input: string) {
  const idx = input.indexOf(":");
  if (idx <= 0) throw new Error("missing chain short name");
  const shortName = input.slice(0, idx);
  const raw = input.slice(idx + 1);

  const chainId = SHORT_NAMES[shortName];
  if (chainId === undefined) throw new Error(`unknown chain: ${shortName}`);

  const address = getAddress(raw); // throws on a bad EIP-55 checksum
  return { shortName, chainId, address };
}

export function formatChainAddress(shortName: string, address: string) {
  return `${shortName}:${getAddress(address)}`;
}
```

发送前检查用户是否处于正确的网络：

```ts
const { chainId, address } = parseChainAddress(userInput);
const net = await provider.getNetwork();
if (net.chainId !== BigInt(chainId)) {
  throw new Error(`address is for chain ${chainId}, wallet is on ${net.chainId}`);
}
```

## 需要注意

- **状态：Draft。** 一些钱包和多签工具非正式地使用这种格式，但提案本身尚未最终确定。
- 前缀只是显示和输入用的元数据。链上没有任何变化：合约和交易仍然使用普通的 20 字节地址。
- 简称来自外部由社区维护的注册表，所以正确性取决于那份列表。规范警告说，外观相似的简称可能被用来迷惑用户。
- 没有前缀的地址仍然需要外部上下文才能知道它指的是哪条链。
- 若需要更通用、同时支持二进制和文本的跨链地址格式，请参阅 [ERC-7930](/eip-7930/)（Interoperable Addresses）。


---

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