EIPs Explained

ERC-7629 · Draft · ERC · 2024-02-18

ERC-7629: ERC-20/ERC-721 Unified Token Interface

A draft single interface for a token that behaves as both an ERC-20 and an ERC-721, letting holders convert between fungible balances and NFTs inside one contract.

What problem does it solve?

Fungible tokens are liquid and easy to trade on DEXs; NFTs are unique and collectible. Some projects want both: an asset that can be traded as a token and also held as a distinct NFT. Existing standards make you pick one, and early hybrid experiments each invented their own function names and events, so wallets and marketplaces could not handle them consistently.

ERC-7629 proposes one interface that covers both behaviours plus explicit conversion between them.

How it works

A compliant contract exposes the familiar functions of both standards, plus some disambiguating ones:

  • Separate views per mode. erc20TotalSupply / erc20BalanceOf report the fungible side; erc721TotalSupply / erc721BalanceOf report the NFT side. owned(owner) lists the NFT IDs an address holds. The plain balanceOf and totalSupply are also present.
  • Shared functions. approve(spender, amountOrId) and transferFrom(from, to, amountOrId) take a number that is either an ERC-20 amount or an ERC-721 token ID; the contract decides which. transfer moves ERC-20 amounts, safeTransferFrom moves NFTs, and setApprovalForAll / isApprovedForAll / getApproved work as in ERC-721.
  • Conversion. erc20ToERC721(amount) turns fungible balance into an NFT; erc721ToERC20(tokenId) turns an NFT back into fungible balance. getUnit() returns the token's unit value used for these conversions. Conversion events are emitted.
  • Events for both worlds. ERC20Transfer, ERC721Transfer, the standard Transfer, Approval, ApprovalForAll, plus conversion events.

The spec also asks for an ERC-20 mode that is about as cheap as a normal token transfer.

Sample code

Converting between modes (ethers v6):

import { Contract } from "ethers";

const token = new Contract(addr, [
  "function getUnit() view returns (uint256)",
  "function erc20BalanceOf(address) view returns (uint256)",
  "function owned(address) view returns (uint256[])",
  "function erc20ToERC721(uint256)",
  "function erc721ToERC20(uint256)",
], signer);

const unit = await token.getUnit();
await (await token.erc20ToERC721(unit)).wait();       // fungible -> NFT

const ids: bigint[] = await token.owned(await signer.getAddress());
await (await token.erc721ToERC20(ids[0])).wait();     // NFT -> fungible
console.log(await token.erc20BalanceOf(await signer.getAddress()));

Things to know

  • Status is Draft, and the interface text has rough edges: an Approval event is declared twice, and the conversion event in the NFT-to-ERC-20 direction reuses the name ERC20ToERC721. Expect changes.
  • Overloading transferFrom / approve with "amount or ID" is ambiguous for generic tools: a value could be read as either. Integrators should use the mode-specific functions and events where possible.
  • balanceOf cannot mean both "token amount" and "NFT count" at once, so the spec adds the erc20… / erc721… variants. Check which one a wallet or indexer relies on.
  • For another approach that keeps the two sides in two linked contracts, see ERC-7631 (Dual Nature Token Pair).

#token #nft #erc20 #erc721 #hybrid

Details

Authors
0xZeus1111 (@0xZeus1111), Nvuwa (@Nvuwa)
Status
Draft
Type
Standards Track / ERC
Created
2024-02-18
Requires

Machine-readable: Markdown · JSON