EIPs Explained

ERC-7631 · Final · ERC · 2024-02-21

ERC-7631: Dual Nature Token Pair

Defines how an ERC-20 token and an ERC-721 collection that mirror each other declare their link, so a balance of fungible tokens automatically corresponds to whole NFTs and apps can discover the pair.

What problem does it solve?

Some projects want one asset to be both fungible and non-fungible: trade it in fractions on a DEX like an ERC-20, but also hold it as individual NFTs on a marketplace. The usual design is two contracts, an ERC-20 and an ERC-721, that keep each other in sync: owning enough ERC-20 units gives you an NFT, and moving the NFT moves those units.

Both contracts can stay fully standard-compliant, but nothing told a wallet, DEX or marketplace that they belong together, and users had no standard way to opt out of NFTs being minted to them. ERC-7631 ("Dual Nature Token Pair") standardises exactly those two things. It is the pattern used by libraries such as DN404.

How it works

By convention the ERC-20 is the base and the ERC-721 is the mirror.

  • Linking. The ERC-20 must implement mirrorERC721() and the ERC-721 must implement baseERC20(). When both return each other's addresses, the pair is confirmed. Before linking, either may return zero or revert. Once a non-zero address is returned it must never change. No ERC-165 check is needed: a non-zero return value is the signal.
  • Skipping NFTs (optional). getSkipNFT(owner) / setSkipNFT(status) and the SkipNFTSet event let an account receive ERC-20 units without NFTs being minted or transferred to it. That matters for liquidity pools, vesting contracts and sale contracts that hold large balances, where minting one NFT per unit would cost O(n) gas and could exceed the block gas limit. A common pattern is to default contracts to "skip".
  • Out of scope. How the two contracts synchronise (which token IDs are minted, burned or moved) and how they get linked are left to implementers.

Sample code

Detecting and verifying a dual-nature pair with ethers v6:

import { Contract, JsonRpcProvider, ZeroAddress } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);

async function findPair(erc20: string) {
  const base = new Contract(erc20, [
    "function mirrorERC721() view returns (address)",
    "function getSkipNFT(address) view returns (bool)",
  ], provider);

  const mirror: string = await base.mirrorERC721().catch(() => ZeroAddress);
  if (mirror === ZeroAddress) return null;

  const nft = new Contract(mirror, ["function baseERC20() view returns (address)"], provider);
  const back: string = await nft.baseERC20();
  if (back.toLowerCase() !== erc20.toLowerCase()) throw new Error("link not mutual");

  return { erc20, erc721: mirror };
}

// Optional: does this account receive NFTs on ERC-20 transfers?
// await base.getSkipNFT(user)   // may revert if unsupported

Opting out of NFTs, from a wallet:

IERC7631BaseNFTSkippable(token).setSkipNFT(true);

Things to know

  • Status: Final.
  • Only the linkage and skip flag are standard. Rules such as "1 NFT per 10^18 ERC-20 units" and which NFT moves on a partial transfer differ by implementation; read the specific contract.
  • Selling ERC-20 units can burn or move your NFTs, and buying can mint ones with random traits. With rarity tiers, people can game reveals by transferring repeatedly; the spec recommends delaying metadata reveal.
  • Sync entry points on each contract must only be callable by its partner contract.
  • This is unrelated to the informal "ERC-404" experiments, which are not an accepted standard.

#token #nft #erc20 #erc721 #fractionalization

Details

Authors
vectorized (@vectorized), Thomas (@0xth0mas), Quit (@quitcrypto), Michael Amadi (@AmadiMichael), cygaar (@cygaar), Harrison (@pop-punk)
Status
Final
Type
Standards Track / ERC
Created
2024-02-21
Requires

Machine-readable: Markdown · JSON