ERC-2876 · Stagnant · ERC · 2020-08-13
ERC-2876: Deposit contract and address standard
A 28-byte deposit address (contract address + 8-byte id with checksum) and a deposit(bytes8) contract interface, so exchanges can tell ETH deposits apart without one account per user.
What problem does it solve?
Exchanges and merchants need to know who sent each ETH deposit. The usual approach is a fresh address per user or invoice, which forces a bad trade-off:
- Externally owned deposit addresses must be hot wallets, or someone has to sweep thousands of cold accounts by hand.
- Deploying a contract per deposit address costs tens of thousands of gas each.
ERC-2876 lets one contract receive all deposits and identifies each depositor by an 8-byte id carried in the calldata. The id is packed into a longer "deposit address" so users still just paste one string into their wallet.
How it works
Deposit address format (28 bytes):
<20-byte contract address> <5-byte nonce> <3-byte checksum>
The checksum is the first 3 bytes of keccak256(address ++ nonce). The nonce plus checksum together form the 8-byte id.
Contract interface:
interface DepositEIP {
function deposit(bytes8 id) external payable returns (bool);
}
- The contract must revert on plain ETH transfers with empty calldata.
depositreturnstruewhen the payment is complete,falsewhen it keeps the funds but the deposit is not yet complete (e.g. a partial invoice payment), and reverts if it does not want the funds.- It should verify the checksum inside the id.
Wallet behaviour: when given a 28-byte deposit address, a wallet must verify the checksum, send to the first 20 bytes, and set calldata to the deposit(bytes8) selector 0x3ef8e69a followed by the 8-byte id, right-padded to 32 bytes. It must refuse if the user also supplied custom data.
Sample code
Turning a deposit address into a transaction (ethers v6):
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 });
Things to know
- Status is Stagnant. Mainstream wallets do not recognise 28-byte deposit addresses.
- It handles native ETH only, not ERC-20 tokens. The author argues separate mechanisms per currency are acceptable.
- Because the contract rejects plain transfers, a wallet that strips the address to 20 bytes and sends without calldata will fail rather than lose funds.
- The 24-bit checksum is stronger than the roughly 15-bit average of EIP-55 mixed-case checksums.
- The spec recommends forwarding funds to a hard-coded or
immutablecold wallet, and using a kill switch that reverts deposits rather thanselfdestructwhen shutting down.