---
eip: 1710
label: ERC-1710
title: URL Format for Web3 Browsers
status: Stagnant
type: Standards Track
category: ERC
created: 2019-01-13
requires: 155
official: https://eips.ethereum.org/EIPS/eip-1710
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1710.md
canonical: https://eips.huatuo.xyz/zh/eip-1710/
lang: zh
tldr: "提议一种带可选链 ID 的 dapp: URL 方案，使去中心化应用的链接可以在用户拥有的任何 web3 浏览器中打开，而不是某个特定厂商的应用。"
tags: [url, deep-link, mobile, web3-browser, wallet]
---

# ERC-1710: URL Format for Web3 Browsers

> A standard way of representing web3 browser URLs for decentralized applications.

**TL;DR:** 提议一种带可选链 ID 的 dapp: URL 方案，使去中心化应用的链接可以在用户拥有的任何 web3 浏览器中打开，而不是某个特定厂商的应用。

## 它解决什么问题？

在移动端，普通浏览器无法运行大多数 dapp，因为它没有注入的钱包。因此 dapp 会通过深度链接把用户带入某个特定钱包的内置浏览器，而每个钱包都有自己的 URL 方案。即使用户已经安装了另一个钱包，dapp 也必须选一个来推荐。

复用 [ERC-831](/eip-831/) 的 `ethereum:` 方案也不合适：许多应用（钱包、身份应用）都会注册它，而在 iOS 上，当多个应用声明同一个方案时，系统会不可预测地选择其中之一，因此链接可能在一个根本没有浏览器的应用中打开。

ERC-1710 为"在 web3 浏览器中打开这个网站"提出了一个专用的、厂商中立的方案。

## 它如何运作

```
dapp:[chain_id@]dapp_url
```

- `dapp_url` 是一个普通的 RFC 3986 URI，书写时不带 `https://` 前缀。
- `chain_id` 是可选的。如果存在，浏览器会在加载页面之前切换到该链 ID（在 [EIP-155](/eip-155/) 中定义），使用户落在正确的网络上。

规范中的示例：`dapp:1@peepeth.com/brunobar79?utm_source=github` 会打开一个 web3 浏览器，选择链 1（主网），然后导航到 `https://peepeth.com/brunobar79?utm_source=github`。

dapp 仍然可以通过延迟深度链接（deferred deep linking）推荐某个特定钱包，但如果用户已经拥有任何支持 `dapp:` 的浏览器，链接就能直接工作。

## 示例代码

构造链接，以及 web3 浏览器可能如何解释它（TypeScript）：

```ts
function toDappLink(url: string, chainId?: number): string {
  const bare = url.replace(/^https?:\/\//, "");
  return chainId !== undefined ? `dapp:${chainId}@${bare}` : `dapp:${bare}`;
}

function parseDappLink(link: string): { chainId?: number; url: string } {
  const m = link.match(/^dapp:(?:(\d+)@)?(.+)$/);
  if (!m) throw new Error("not a dapp: URL");
  return { chainId: m[1] ? Number(m[1]) : undefined, url: `https://${m[2]}` };
}

toDappLink("https://app.example.org/swap", 10);
// "dapp:10@app.example.org/swap"

parseDappLink("dapp:1@peepeth.com/brunobar79?utm_source=github");
// { chainId: 1, url: "https://peepeth.com/brunobar79?utm_source=github" }
```

dapp 可以向移动端访客展示的 HTML 链接：

```html
<a href="dapp:1@app.example.org/">Open in your web3 browser</a>
```

## 需要注意

- **状态：Stagnant。** 支持情况取决于钱包是否注册了 `dapp:` 方案；在依赖它之前，请逐个检查目标钱包。
- 规范没有说明打开目标时应使用 `http` 还是 `https`；示例暗示使用 `https`。
- 如果 dapp 的 URL 本身以用户信息（`user@host`）开头，`@` 分隔符可能产生歧义。请避免这样的 URL。
- 如今，许多 dapp 转而通过 WalletConnect（[ERC-1328](/eip-1328/)）或各钱包专属的通用链接（universal link）连接移动钱包。对于支付请求，请使用 [ERC-681](/eip-681/)。


---

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