ERC-6604 Abstract token

Draft · Tokens · created 2023-03-03

A standard that lets tokens be issued off-chain as messages at no cost, and brought on-chain or reverted back into a message only when needed.

Why it is needed

Distributing tokens usually requires the issuer or recipient to execute an issuance transaction on-chain, incurring a fee each time. For services that distribute tokens to tens of thousands of people, such as airdrops, proof-of-attendance tokens, or access credentials, this cost is a significant burden. The Merkle tree approach, which shifts the cost to the recipient, is commonly used, but it is inconvenient because users must obtain and submit a Merkle proof themselves, and claim methods differ by project. There is also no common interface for wallets or apps to recognize and display potential tokens that have not yet been put on-chain. This standard aims to solve this by allowing token information to be queried and brought on-chain the same way regardless of which proof method is used.

What to implement

In depth

Token message structure

The AbstractTokenMessage struct bundles a token together with the context needed to reify it. chainId and implementation scope which chain and which contract the message can be reified on. owner is the address that will own the token once it is reified. meta is implementation-specific context such as id, amount, and uri, and proof is an implementation-specific proof authorizing reification. nonce is a counter appended to distinguish multiple messages that are otherwise identical. The reason meta and proof are typed as bytes is covered in the Rationale: apps can query the contract instead of interpreting these fields directly, the implementation contract can decode them into a struct internally for verification, and the fields can hold any proof format, whether an array of merkle nodes or a 65 byte signature.

Message status

The AbstractTokenMessageStatus enum is defined per (contract, message) pair. invalid means the contract cannot interact with that message, valid means it can, and used means the interaction has already happened. Anyone can query this via the status function, so wallets or apps can check whether a message is usable before spending it.

Rules for reify

reify is the function that moves the token defined in a message into the contract. A contract MUST reify a valid token message. Reification must be idempotent, meaning a given message can be used to reify a token at most once. Calling reify with an already-used message MAY succeed or MAY revert. When a message is reified, a Reify event MUST be emitted.

Rules for dereify

dereify is an optional function that converts a token held in the contract back into a message targeting another contract or chain. It allows a token to be moved by dereifying it in one context and reifying it in another. If implemented, it MUST burn from the holder exactly the token defined in the message, and MUST NOT dereify a message that targets the same contract and same chain. Dereification must also be idempotent, and calling it on an already-used message may succeed or revert. A Dereify event MUST be emitted when a token is dereified into a message.

Query functions and ERC-165

id, amount, and uri are all optional functions. An implementation without a token id, like ERC-20, may return 0 for id or omit it entirely; an implementation without an amount, like ERC-721, may omit amount the same way; and an implementation without a uri, like ERC-20, may omit uri the same way. These query functions let users read the contents of their potential tokens without knowing which proof scheme the implementation uses. Every abstract token contract must support ERC-165 and include the abstract token interface ID in its supported interfaces.

Integration with existing token standards

An abstract token that is compatible with an existing standard must overload the existing transfer functions to support transferring from a message. IAbstractERC20 adds versions of transfer and transferFrom that take an AbstractTokenMessage argument, reifying the message first and then transferring. IAbstractERC721 adds the same message argument to safeTransferFrom and transferFrom, and IAbstractERC1155 adds it to safeTransferFrom and safeBatchTransferFrom in the same way. Batch transfers take an array of messages. This lets a received message be brought onchain and sent to another address in a single step.

Proposal status

This proposal has been in Draft status since March 2023. Its contents may change or stall, so check the latest status before implementing or depending on it.

Things to watch out for

Original ERC · ← ERCs