ERC-7629 ERC-20/721 unified token interface (ERC-20/ERC-721 Unified Token Interface)

Draft · Tokens · created 2024-02-18

A standard that lets a single contract have both the liquidity of ERC-20 and the uniqueness of ERC-721, by combining the functionality of both standards into a single interface and defining a way to switch between the two modes.

Why it is needed

Ethereum has separate standards for fungible tokens (ERC-20) and NFTs, where each token is unique (ERC-721). Today these two are completely separate, so building an asset that needs both liquidity, which is easy to divide and trade, and unique ownership forces a choice between the two. Developers also have to implement different functions and logic for each token type separately, making integration cumbersome and reducing interoperability between apps. This standard tries to fill that gap by defining, in a single interface, the set of functions common to both token types, and by supporting switching between ERC-20 state and ERC-721 state.

What to implement

In depth

Combining both standards in a single contract

A contract following this standard MUST implement both ERC-20 and ERC-721 functionality together in a single contract, and MUST implement the proposed IERC7629 interface. The interface inherits from IERC165 and includes the transfer, approval, and lookup functions of both standards along with conversion functions and related events. In ERC-20 mode, it specifies that gas consumption should be as low as that of ordinary ERC-20 transfers. The requires field lists ERC-20, ERC-165, and ERC-721.

amountOrId: a single argument that doubles as both amount and token ID

approve(spender, amountOrId) and transferFrom(from, to, amountOrId) serve both standards with a single argument. If the value is interpreted as an ERC-20 amount, it approves or transfers that quantity; if interpreted as an ERC-721 token ID, it approves or transfers that NFT. By contrast, transfer(to, amount) is ERC-20-only, and the two safeTransferFrom variants are reserved for ERC-721 only. safeTransferFrom is specified so that if the recipient is a contract (code size > 0), it calls onERC721Received and reverts unless the expected return value is received.

Mode conversion: erc20ToERC721 and erc721ToERC20

erc20ToERC721(amount) converts a specified amount of ERC-20 tokens into an ERC-721 token, and erc721ToERC20(tokenId) converts a single NFT back into ERC-20 tokens. getUnit() is a lookup function that returns the unit value associated with the token. Conversion is signaled via the ERC20ToERC721 event, though the original interface declares two events with the same name, and the second one (which carries uint256[] tokenIds) is marked in comments as being for converting from ERC-721 to ERC-20.

Duplicated balance lookups and backward compatibility

ERC-20's balanceOf returns a quantity balance, while ERC-721's balanceOf returns the count of tokens held, so the same name is used with two different meanings. The original text identifies this as the key point of conflict for backward compatibility and proposes providing separate functions matching each standard's convention. The interface has separate erc20BalanceOf, erc721BalanceOf, erc20TotalSupply, and erc721TotalSupply functions, while the shared balanceOf and totalSupply are documented in comments as following the ERC-20 convention. owned(owner) is a helper lookup function that returns the array of NFT IDs held by an address.

Design rationale: common functions to resolve fragmentation

The original Rationale section cites standardizing functions such as transferFrom, mint, and burn so developers don't need to implement different logic per token type as its goal. It describes mint and burn for managing token supply and lifecycle, and balanceOf and ownerOf for balance and ownership lookups, as the core components, and also mentions compatibility with existing ERC-20/ERC-721 implementations and the potential for future function and event extensions. However, mint and burn are only mentioned in the Rationale and are not declared in the interface code.

A proposal still at the Draft stage

This document is a Draft-status proposal created on February 18, 2024. The content may still change and is not a finalized standard, so you should check the latest original text before implementing or integrating it.

Things to watch out for

Original ERC · ← ERCs