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
event ERC20ToERC721(address indexed to, uint256 amount, uint256 tokenId);: Signals that an ERC-20 token has been converted into an ERC-721 token.event ERC20ToERC721(address indexed to, uint256 amount, uint256[] tokenIds);: Per the original comment, this is the event that signals conversion from ERC-721 to ERC-20, and it carries an array of the converted token IDs.function name() external view returns (string memory);: Returns the name of the token.function symbol() external view returns (string memory);: Returns the token's symbol.function decimals() external view returns (uint8);: Returns the number of decimals the token uses.function totalSupply() external view returns (uint256);: Returns the total supply of the ERC-20 token.function balanceOf(address owner) external view returns (uint256);: Returns the ERC-20 token balance held by an address.function erc20TotalSupply() external view returns (uint256);: Returns the total supply of the ERC-20 token.function erc20BalanceOf(address owner) external view returns (uint256);: Returns the ERC-20 token balance of an address.function erc721TotalSupply() external view returns (uint256);: Returns the total supply of the ERC-721 token.function erc721BalanceOf(address owner) external view returns (uint256);: Returns the number of ERC-721 tokens held by an address.function getApproved(uint256 tokenId) external view returns (address);: Returns the address approved for a specific NFT, and reverts if the NFT is invalid.function owned(address owner) external view returns (uint256[] memory);: Returns the array of ERC-721 token IDs owned by an address.function ownerOf(uint256 tokenId) external view returns (address erc721Owner);: Returns the owner address of a specific ERC-721 token.function tokenURI(uint256 tokenId) external view returns (string memory);: Returns the metadata URI of a specific ERC-721 token.function setApprovalForAll(address operator, bool approved) external;: Sets or revokes an operator's approval over all tokens.function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external payable;: Safely transfers an NFT, checking the return value of onERC721Received if the recipient is a contract, and reverting otherwise.function safeTransferFrom(address from, address to, uint256 tokenId) external payable;: Same as the function above, but transfers the NFT leaving the extra data empty.function transfer(address to, uint256 amount) external returns (bool);: Sends a specified amount of ERC-20 tokens to another address.function getUnit() external view returns (uint256);: Returns the unit value associated with the token.function erc721ToERC20(uint256 tokenId) external;: Converts a single ERC-721 token into ERC-20 tokens.function erc20ToERC721(uint256 amount) external;: Converts a specified amount of ERC-20 tokens into an ERC-721 token.
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
- Interpretation differences arising from the dual nature: Because a single contract carries both ERC-20 and ERC-721 characteristics, protocol interpretations may diverge. This point must be carefully considered during development.
- Audit recommendation for mode switching: A comprehensive security audit is recommended to protect user assets. Particular emphasis is placed on checking the moment users switch between the two modes.