---
eip: 1328
label: ERC-1328
title: WalletConnect URI Format
status: Final
type: Standards Track
category: ERC
created: 2018-08-15
official: https://eips.ethereum.org/EIPS/eip-1328
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1328.md
canonical: https://eips.huatuo.xyz/zh/eip-1328/
lang: zh
tldr: "定义 wc: URI，dapp 将其显示为二维码或链接，钱包即可据此与它建立加密的 WalletConnect 会话。"
tags: [walletconnect, uri, wallet, qr-code, connection]
---

# ERC-1328: WalletConnect URI Format

> Define URI format for initiating connections between applications and wallets

**TL;DR:** 定义 wc: URI，dapp 将其显示为二维码或链接，钱包即可据此与它建立加密的 WalletConnect 会话。

## 它解决什么问题？

运行在桌面浏览器中的 dapp 常常需要与手机上的钱包，或同一设备上的另一个钱包应用通信。在任何请求能够传递之前，双方需要一种方式来找到彼此并就加密密钥达成一致。

WalletConnect 通过让 dapp 显示一个简短的 URI 来解决这个问题，通常是二维码或深度链接。钱包扫描或打开它，加入同一个通道，此后双方交换加密消息。ERC-1328 标准化了该 URI 的格式，使任何钱包都能解析它。

WalletConnect 早期的 alpha 版本把 JSON 放进二维码。改用 URI 使解析更简单，也让移动操作系统可以把链接路由到正确的应用（例如通过 Android intent）。

## 它如何运作

语法为：

```
wc:<topic>[@<version>][?<key>=<value>&...]
```

- `topic`：标识双方将使用的通道。
- `version`：WalletConnect 协议版本。版本号是格式的一部分，以便协议可以演进。
- 参数取决于版本。

**版本 1：**

| 参数 | 含义 |
| --- | --- |
| `key` | 用于加密的对称密钥 |
| `bridge` | 中继消息的桥接服务器 URL |

**版本 2：**

| 参数 | 含义 |
| --- | --- |
| `symKey` | 用于加密经中继传输的消息的对称密钥 |
| `methods` | 配对主题所支持的 JSON-RPC 方法 |
| `relay-protocol` | 用于中继消息的传输协议 |
| `relay-data` | 可选的传输数据 |
| `expiryTimestamp` | 可选的配对过期 Unix 时间（秒） |

## 示例代码

v2 URI 的形式（占位值）：

```
wc:<64-hex-topic>@2?relay-protocol=irn&symKey=<64-hex-key>&expiryTimestamp=1705934757
```

用 TypeScript 解析：

```ts
function parseWcUri(uri: string) {
  const m = uri.match(/^wc:([^@?]+)(?:@(\d+))?(?:\?(.*))?$/);
  if (!m) throw new Error("not a WalletConnect URI");
  const [, topic, version, query = ""] = m;
  const params = Object.fromEntries(new URLSearchParams(query));
  return { topic, version: version ? Number(version) : undefined, params };
}

const { topic, version, params } = parseWcUri(scannedText);
if (version === 2) {
  console.log(topic, params["relay-protocol"], params.expiryTimestamp);
}
```

在实际应用中你不会自己解析它：WalletConnect SDK 在 dapp 端生成该 URI，并在钱包端处理它。

## 需要注意

- **状态：Final。** URI 格式本身是稳定的；参数的含义与协议版本绑定。
- URI 中携带对称会话密钥，因此应将其视为短期有效，并且只向正在连接的用户显示。它不包含也不会暴露用户的私钥。
- 版本 1 依赖桥接服务器，已被 WalletConnect 淘汰；当前的集成使用版本 2。
- 对于支付请求而不是会话配对，请参阅 [ERC-681](/eip-681/) 和 [ERC-831](/eip-831/) 中的 `ethereum:` URI 格式。连接之后，dapp 通常通过 [EIP-1193](/eip-1193/) 风格的提供者与钱包通信。


---

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