---
eip: 2876
label: ERC-2876
title: Deposit contract and address standard
status: Stagnant
type: Standards Track
category: ERC
created: 2020-08-13
official: https://eips.ethereum.org/EIPS/eip-2876
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2876.md
canonical: https://eips.huatuo.xyz/zh/eip-2876/
lang: zh
tldr: 一种 28 字节的充值地址（合约地址 + 带校验和的 8 字节 id）和 deposit(bytes8) 合约接口，让交易所无需为每个用户开一个账户就能区分 ETH 充值。
tags: [payments, deposits, address-format, exchange, erc]
---

# ERC-2876: Deposit contract and address standard

> This ERC defines a simple contract interface for managing deposits. It also defines a new address format that encodes the extra data passed into the interface's main deposit function.

**TL;DR:** 一种 28 字节的充值地址（合约地址 + 带校验和的 8 字节 id）和 deposit(bytes8) 合约接口，让交易所无需为每个用户开一个账户就能区分 ETH 充值。

## 它解决什么问题？

交易所和商户需要知道每笔 ETH 充值来自谁。常见做法是为每个用户或每张账单分配一个新地址，但这带来了糟糕的取舍：

- 外部拥有账户（EOA）形式的充值地址必须是热钱包，否则就得有人手动归集成千上万个冷账户。
- 为每个充值地址部署一个合约，每个要花费数万 gas。

ERC-2876 让一个合约接收所有充值，并通过 calldata 中携带的 8 字节 id 识别每位充值者。该 id 被打包进一个更长的"充值地址"，因此用户依然只需把一个字符串粘贴到钱包里。

## 它如何运作

**充值地址格式（28 字节）：**

```
<20-byte contract address> <5-byte nonce> <3-byte checksum>
```

校验和是 `keccak256(address ++ nonce)` 的前 3 个字节。nonce 加校验和共同构成 8 字节的 `id`。

**合约接口：**

```solidity
interface DepositEIP {
    function deposit(bytes8 id) external payable returns (bool);
}
```

- 合约必须对 calldata 为空的普通 ETH 转账执行 revert。
- 当付款完成时 `deposit` 返回 `true`；当它保留资金但充值尚未完成时（例如账单只付了一部分）返回 `false`；如果不想接收这笔资金则 revert。
- 它应当校验 id 中的校验和。

**钱包行为：** 收到 28 字节的充值地址时，钱包必须校验校验和，向前 20 个字节发送，并将 calldata 设为 `deposit(bytes8)` 的选择器 `0x3ef8e69a`，后接右侧补零到 32 字节的 8 字节 id。如果用户还提供了自定义数据，则必须拒绝。

## 示例代码

把充值地址转换为交易（ethers v6）：

```ts
import { keccak256, getBytes, hexlify, concat, zeroPadBytes } from "ethers";

function parseDepositAddress(dep: string) {
  const b = getBytes(dep);
  if (b.length !== 28) throw new Error("not a deposit address");
  const addr = b.slice(0, 20), nonce = b.slice(20, 25), chk = b.slice(25, 28);
  const expected = getBytes(keccak256(concat([addr, nonce]))).slice(0, 3);
  if (hexlify(expected) !== hexlify(chk)) throw new Error("bad checksum");
  const id = b.slice(20, 28);
  return {
    to: hexlify(addr),
    data: concat(["0x3ef8e69a", zeroPadBytes(id, 32)]),
  };
}

// Test vector from the spec
const tx = parseDepositAddress("0x433e064c42e87325fb6ffa9575a34862e0052f26913fd924f056cd15");
// tx.to   = 0x433e064c42e87325fb6ffa9575a34862e0052f26
// tx.data = 0x3ef8e69a913fd924f056cd15000000000000000000000000000000000000000000000000
await signer.sendTransaction({ ...tx, value: amount });
```

## 需要注意

- 状态为 **Stagnant**。主流钱包不识别 28 字节的充值地址。
- 它只处理原生 ETH，不处理 ERC-20 代币。作者认为每种货币使用各自的机制是可以接受的。
- 由于合约拒绝普通转账，把地址截断为 20 字节并且不带 calldata 发送的钱包会失败，而不会损失资金。
- 24 位的校验和比 [EIP-55](/eip-55/) 大小写混合校验和平均约 15 位的强度更高。
- 规范建议将资金转发到硬编码的或 `immutable` 的冷钱包，并且在关闭时使用会 revert 充值的 kill switch，而不是 `selfdestruct`。


---

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