---
eip: 2400
label: ERC-2400
title: Transaction Receipt URI
status: Stagnant
type: Standards Track
category: ERC
created: 2019-11-05
requires: 155, 681
official: https://eips.ethereum.org/EIPS/eip-2400
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2400.md
canonical: https://eips.huatuo.xyz/zh/eip-2400/
lang: zh
tldr: "一种 URI 格式 ethereum:tx-<hash>@<chainId>，用于分享已提交的交易，并附带解码它所需的方法和事件签名。"
tags: [uri, transactions, wallet, interop, qr]
---

# ERC-2400: Transaction Receipt URI

> URI format for submitted transactions with complete information for transaction decoding

**TL;DR:** 一种 URI 格式 ethereum:tx-<hash>@<chainId>，用于分享已提交的交易，并附带解码它所需的方法和事件签名。

## 它解决什么问题？

单独一个交易哈希看起来和其他任何 32 字节哈希没有区别。它没有说明自己属于哪条链，而且从未见过该合约的查看者无法解码 calldata 或日志。

ERC-2400 为「已提交的交易」定义了标准 URI。钱包、dapp、聊天应用，甚至自动售货机上的二维码都可以传递它，接收方会用用户偏好的浏览器打开，并带上足够的上下文来有意义地展示这笔交易。它是 [EIP-681](/eip-681/) 在回执一侧的配套规范，后者描述的是交易*请求*。

## 它如何运作

语法（简化）：

```
ethereum:tx-<0x + 64 hex chars>[@<chainId>][?method=<sig>&events=<sig>;<sig>...]
```

- **`tx-` 前缀**表明该 URI 是一份回执。将来不兼容的格式必须使用另一个以短横线分隔的前缀。
- **交易哈希**是必需的。客户端在给定的链上查找它；如果找不到，就检查待处理池并持续轮询。如果仍然找不到，则显示「transaction not found」错误。
- **`@chainId`** 是 [EIP-155](/eip-155/) 中的十进制链 ID。省略时默认为主网（`1`）。
- **`method`** 是函数签名，例如 `transfer(address,uint256)`。客户端必须检查其 4 字节选择器是否与 calldata 的前 4 个字节一致，否则显示验证错误。
- **`events`** 是以 `;` 分隔的事件签名列表。类型前的 `!` 表示 indexed 参数。对于成功的交易，列出的每个事件必须在回执日志中至少出现一次；待处理和失败的交易不会按事件进行检查。

其思路是：签署该交易的人本来就知道 ABI，所以分享时可以附上相关片段。

## 示例代码

规范中的 URI：

```text
ethereum:tx-0x1143b5e38fe3cf585fb026fb9b5ce35c85a691786397dc8a23a07a62796d8172@1

ethereum:tx-0x5375e805b0c6afa20daab8d37352bf09a533efb03129ba56dee869e2ce4f2f92@1?method="transfer(address,uint256)"&events="Transfer(!address,!address,uint256)"
```

针对获取到的交易验证 `method` 参数（ethers v6）：

```ts
import { JsonRpcProvider, id } from "ethers";

declare const receiptUri: string;
declare function rpcUrlFor(chainId: number): string; // your own chain -> RPC map

const uri = new URL(receiptUri.replace("ethereum:tx-", "https://x/")); // reuse URL parser
const [hash, chain = "1"] = uri.pathname.slice(1).split("@");
const method = uri.searchParams.get("method")?.replace(/"/g, "");

const provider = new JsonRpcProvider(rpcUrlFor(Number(chain)));
const tx = await provider.getTransaction(hash);
if (method && tx && tx.data.slice(0, 10) !== id(method).slice(0, 10)) {
  throw new Error("method validation error");
}
```

## 需要注意

- **状态：Stagnant。** 钱包和浏览器对该格式的实现并不普遍；请把它当作参考设计，而不是客户端都能理解的东西。
- 规范说要持续检查待处理交易，直到它「不可回滚」，建议约 12 个区块。在合并（Merge）之后的以太坊上，最终性是另一个共识层面的概念，因此实现者应自行决定显示什么样的确认阈值。
- 找不到哈希可能只是因为交易仍在传播，或者它已被同一 nonce 的另一笔交易替换。
- URI 中的签名是分享者提供的提示，不能证明任何事情。客户端必须像规范要求的那样，对照实际的链上数据进行验证。


---

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