ERC-1996 · Stagnant · ERC · 2019-04-10
ERC-1996: Holdable Token
An ERC-20 extension that lets tokens be put on hold for a payee, with a notary deciding whether to execute or release, guaranteeing a future payment like a card pre-authorization.
What problem does it solve?
ERC-20's approve lets someone else move your tokens later, but it does not reserve them. You can still spend the approved balance, so the payment is not guaranteed.
Many real payment flows need a guarantee first:
- A hotel pre-authorizes an amount at check-in and charges the actual bill at check-out.
- A regulated token must check a transfer before it settles, while making sure the funds are still there afterwards.
ERC-1996 adds holds: an amount is locked from the payer's spendable balance, earmarked for a payee, and later either transferred or returned.
How it works
A hold has a payer, a payee, a maximum amount, a notary and an expiry. Each hold is identified by a caller-chosen operationId string, which must not be reused.
- Create:
hold(...)by the payer, orholdFrom(...)by an operator the payer has authorized withauthorizeHoldOperator. The amount stops being transferable immediately. - Execute: only the notary can call
executeHold(operationId, value). It transfersvalue(at most the held amount) to the payee; any remainder is released back to the payer. This is the hotel's "charge the actual bill". - Release: before expiry, the notary or the payee can release; after expiry, anyone can. Nothing is transferred.
- Renew: the payer or operator can extend a hold that has not yet expired.
- Perpetual holds: a
timeToExpirationof 0 means no expiry, so only the notary can execute, and only the notary or payee can release.
balanceOf, transfer and transferFrom must exclude held tokens. balanceOnHold, totalSupplyOnHold and retrieveHoldData expose the held state, and each step emits an event (HoldCreated, HoldExecuted, HoldReleased, HoldRenewed).
Sample code
Part of the interface, and a merchant flow:
interface IHoldable /* is IERC20 */ {
enum HoldStatusCode { Nonexistent, Ordered, Executed, ReleasedByNotary, ReleasedByPayee, ReleasedOnExpiration }
function hold(string calldata operationId, address to, address notary, uint256 value, uint256 timeToExpiration) external returns (bool);
function holdFrom(string calldata operationId, address from, address to, address notary, uint256 value, uint256 timeToExpiration) external returns (bool);
function executeHold(string calldata operationId, uint256 value) external returns (bool);
function releaseHold(string calldata operationId) external returns (bool);
function balanceOnHold(address account) external view returns (uint256);
function authorizeHoldOperator(address operator) external returns (bool);
}
// ethers v6: guest pre-authorizes 300 tokens for 3 days; hotel is payee and notary
await token.connect(guest).hold("booking-8812", hotel, hotel, parseUnits("300", 18), 3 * 24 * 3600);
// at check-out the hotel charges only 240; 60 becomes spendable again for the guest
await token.connect(hotel).executeHold("booking-8812", parseUnits("240", 18));
Things to know
- Status: Stagnant. It was proposed as the base of a family of related standards: Clearable, Fundable, E-Money and Payoutable tokens, all also stagnant.
- The notary has full control over whether the payee gets paid. Choose it with care; it can be the payee, an independent party or a contract.
- The spec text has small inconsistencies:
holdFromrefers to anapproveToHoldfunction, while the interface names itauthorizeHoldOperator, andnetBalanceOfis described asbalanceOfplusbalanceOnHold(that is, the total including held tokens). Clarify these before building. - Using
stringoperation IDs is flexible but costs more gas than abytes32key.