ERC-7699 · Draft · ERC · 2024-04-26
ERC-7699: ERC-20 Transfer Reference Extension
Adds transfer and transferFrom overloads with a bytes reference to ERC-20 tokens, logging a bytes32 TransferReference event so payments can be matched to invoices and orders.
What problem does it solve?
Bank transfers almost always carry a reference: SWIFT MT103 has "Remittance Information", ISO 20022 / SEPA has RmtInf. A merchant uses it to know which invoice a payment settles.
A plain ERC-20 transfer carries only sender, recipient and amount. Merchants that accept tokens today either give each customer a unique deposit address, run a custom payment-proxy contract, or reconcile off-chain. ERC-7699 lets the token itself carry a payment reference in a standard way.
How it works
A token implementing the extension adds two overloaded functions and one event:
transfer(to, amount, transferReference)transferFrom(from, to, amount, transferReference)event TransferReference(bytes32 indexed loggedReference)
Rules from the spec:
- When
transferReferenceis non-empty, the token MUST emitTransferReferenceand then the normal ERC-20Transferevent, ideally immediately after, so a client can pair them. - When
transferReferenceis empty,TransferReferenceMUST NOT be emitted: the call behaves exactly like a regular transfer. - The input is unbounded
bytes(it could hold structured data or a signature), but the logged value isbytes32. The implementer decides how to derive it: a copy of a short reference, a hash, or something else. Consumers must not assume the two are equal. - The event is indexed and must not be
anonymous, so wallets and indexers can filter by reference. - Zero-amount transfers still emit the event.
- The ERC-165 interface ID is
0x1522573a.
Sample code
Minimal implementation on top of OpenZeppelin's ERC20 (based on the reference implementation):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract InvoiceToken is ERC20 {
event TransferReference(bytes32 indexed loggedReference);
constructor() ERC20("Invoice Token", "INV") {
_mint(msg.sender, 1_000_000e18);
}
function transfer(address to, uint256 amount, bytes calldata ref) external returns (bool) {
_logReference(ref);
return transfer(to, amount); // emits ERC-20 Transfer right after
}
function transferFrom(address from, address to, uint256 amount, bytes calldata ref)
external returns (bool)
{
_logReference(ref);
return transferFrom(from, to, amount);
}
function _logReference(bytes calldata ref) internal {
if (ref.length == 0) return; // MUST NOT emit for empty refs
emit TransferReference(keccak256(ref)); // derivation is implementation-defined
}
}
Paying an invoice from TypeScript (ethers v6). The overload must be selected by signature:
const token = new Contract(TOKEN, [
"function transfer(address,uint256,bytes) returns (bool)",
], wallet);
await token["transfer(address,uint256,bytes)"](merchant, parseUnits("25", 18), toUtf8Bytes("INV-2024-0002"));
Things to know
- Status: Draft. The interface may still change, and few tokens implement it.
- References are public on-chain. Even a short invoice number can leak business information; consider hashing or encrypting sensitive references.
- Anyone can send a payment with any reference, including one belonging to someone else's invoice. Merchants should check the sender and amount, not just the reference.
- Existing tokens can only gain this feature if they are upgradeable; the spec notes it does not affect storage layout.