ERC-823 Token Exchange Standard

Stagnant · Tokens · created 2018-01-06

A standard that lets an ERC20 token holder exchange their tokens for another registered ERC20 token, and immediately spend the exchanged tokens as payment.

Why it is needed

The ERC20 standard itself has no function for converting one token into another. As a result, exchanging tokens requires relying on a separate token converter, and existing converters work by burning the original token during the exchange, reducing total supply. A design where tokens are destroyed cannot be treated like currency, and it also weakens the incentive to create new tokens. In addition, spending the exchanged tokens immediately as payment requires handling the exchange and the spend as two separate steps. Without such a standard, every project implements exchange logic differently, making it difficult for a compatible exchange mechanism between ERC20 tokens to take hold.

What to implement

In depth

Sender Interface

The interface implemented by an ERC20 contract that wants to exchange its own tokens for another token. The exchangedWith mapping accumulates how much (uint) has been exchanged with which target contract (address), and the exchangedBy mapping records the exchange amount per address of the person who requested the exchange. exchangeToken(_targetContract, _amount) calls the exchange service contract to initiate the exchange and returns success and creditedAmount. exchangeAndSpend(_targetContract, _amount, _to) requests that the converted amount be spent to the _to address at the same time as the exchange. __exchangerCallback(_targetContract, _exchanger, _amount) is a callback that only the exchange service contract can call, deducting _amount from the exchanger's balance. This process is recorded via the Exchange and ExchangeSpent events.

Receiver Interface

The interface implemented by an ERC20 contract that receives tokens exchanged from another token. The exchangesReceived mapping records how much (uint) has been received and held from which token (address). __targetExchangeCallback(_to, _amount) can only be called by the exchange service contract, and credits _amount of the target token to the exchanger's address, completing the exchange. __targetExchangeAndSpendCallback(_from, _to, _amount) credits the amount and simultaneously transfers the token to the _to address, finishing the exchange and spend in one step. Both callbacks record their results via the Exchange and ExchangeSpent events.

Exchange Service Contract

A separate contract that acts as the intermediary between the sender and receiver sides. It uses an oracle to obtain the authenticated exchange rate. The registeredTokens array is the list of tokens registered to participate in exchanges, and a token must be registered in this list before it can be exchanged. registerToken(_token) is the function a token contract owner uses to register their own token. exchangeToken(_targetContract, _amount, _from) looks up the exchange rate to calculate the converted amount, then calls the sender's __exchangerCallback and the receiver's __targetExchangeCallback in sequence to complete the exchange. exchangeAndSpend(_targetContract, _amount, _from, _to) follows the same process but also includes the spend, calling __targetExchangeAndSpendCallback. The result is recorded via the Exchange and ExchangeAndSpent events.

A design that does not burn tokens

Existing token converters worked by burning the original token during exchange, reducing total supply. This standard instead does not burn the exchanged token, keeping it held inside the target contract so it can be reused or preserved later. The specification describes this as closer to how currency is handled compared to existing token converters, and states that this structure is an exchange standard that can be applied consistently across all ERC20 tokens.

Backward compatibility with ERC20

Because this proposal simply extends the ERC20 standard, it is fully backward compatible. A token implementing this standard still follows all the existing functionality of the ERC20 standard, and the specification explains that this standard merely adds exchange and spend functionality on top of it. However, it should be noted that the specification's status is Stagnant, a draft proposed in 2018 that has not progressed further and has stalled.

Things to watch out for

Original ERC · ← ERCs