ERC-823 · Stagnant · ERC · 2018-01-06
ERC-823: Token Exchange Standard
A proposed extension to ERC-20 that lets holders swap one registered token for another through an oracle-priced exchange service and spend the result, keeping the original tokens instead of burning them. Stagnant.
What problem does it solve?
In early 2018, if you held token A but a merchant wanted token B, there was no standard way to pay. The spec notes that the "token converters" of the time did the swap by destroying (burning) the input tokens, which shrinks token A's supply.
ERC-823 proposes a different model. Tokens that are swapped are not burned. They are stored inside the target token's contract. Token B's contract then holds a reserve of token A, much as a bank holds foreign currency, and the user receives token B to keep or spend right away.
How it works
There are three roles. Each is a set of functions and events that an ERC-20 contract (or a separate service) adds:
| Role | Key functions | What it does |
|---|---|---|
| Sender token (token A) | exchangeToken(target, amount), exchangeAndSpend(target, amount, to), __exchangerCallback(...) |
Starts a swap. The callback deducts the user's A balance and records which target contract now holds it. |
| Receiver token (token B) | __targetExchangeCallback(to, amount), __targetExchangeAndSpendCallback(from, to, amount) |
Credits the user (or the payee directly) with B. |
| Exchange service | registerToken(token), exchangeToken(...), exchangeAndSpend(...) |
Keeps the list of registered tokens, gets the rate from an oracle, and calls both callbacks. |
The callbacks may be called only by the exchange service contract. Only registered tokens can take part. Every function returns bool success, and callers must handle false.
Sample code
The sender-side interface, adapted from the spec (the spec's typos fixed):
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;
interface IERC823Sender {
event Exchange(address from, address targetContract, uint256 amount);
event ExchangeSpent(address from, address targetContract, address to, uint256 amount);
function exchangeToken(address targetContract, uint256 amount)
external returns (bool success, uint256 creditedAmount);
function exchangeAndSpend(address targetContract, uint256 amount, address to)
external returns (bool success);
/// MUST only be callable by the exchange service.
function __exchangerCallback(address targetContract, address exchanger, uint256 amount)
external returns (bool success);
}
Paying a merchant in token B while holding token A:
await tokenA.exchangeAndSpend(TOKEN_B_ADDRESS, amountInB, merchantAddress);
Things to know
- This proposal is Stagnant and was never adopted. No major token implements it.
- The design relies on a trusted exchange-service contract and an oracle for prices. Both are central points of trust and attack. The spec does not define either.
- The spec text has several typos and inconsistencies. For example,
__targetExchangeCallbacktakesuint _toinstead of an address, and theexchangeAndSpenddescription mentions a return value that the signature does not have. Any implementation would have to resolve these. - In practice, swapping and paying in another token is done today by separate exchange contracts (DEXs and aggregators) that work with plain ERC-20 tokens. Token contracts do not need to know about each other.