EIPs Explained

ERC-998 · Draft · ERC · 2018-07-07

ERC-998: Composable Non-Fungible Token

A Draft extension that lets an ERC-721 NFT own other NFTs and ERC-20 balances, forming trees that move together when the top token is transferred.

What problem does it solve?

An ERC-721 token can be owned only by an address. Many designs want tokens that hold other tokens: a game character that owns its sword and armour, a bundle of NFTs sold as one item, or an NFT that carries a token balance. Without a standard, each project invents its own nesting scheme, and wallets and marketplaces cannot see what is inside.

ERC-998 defines composable NFTs. Tokens form a tree with one address at the root, and moving the root token moves everything under it in one transaction.

How it works

There are four interfaces. A contract may implement more than one.

Interface Kind What it does
ERC998ERC721TopDown ERC-721 parent Holds and transfers child ERC-721 tokens
ERC998ERC20TopDown ERC-721 parent Holds and transfers ERC-20 balances
ERC998ERC721BottomUp ERC-721 child Records which parent token it belongs to
ERC998ERC20BottomUp ERC-20 child Lets balances be owned by an ERC-721 token

Top-down parents track their children. Any ordinary ERC-721 can be added as a child. Bottom-up children track their parent, so they can attach to any ordinary ERC-721.

Key behaviour:

  • Adding a child. Call safeTransferFrom(from, composable, childId, data) on the child's contract, with the parent token ID in data. The composable's onERC721Received records it. For older NFTs without safeTransferFrom, approve and then call getChild.
  • Removing a child uses explicit functions such as transferChild(fromTokenId, to, childContract, childTokenId). They always name from, to and what.
  • Plain transferFrom must fail for a token that is owned by another token. This stops an operator moving it without saying which parent it comes from.
  • Root owner. rootOwnerOf(tokenId) walks up the tree and returns a bytes32: the magic value 0xcd740db5 in the first 4 bytes and the owner address in the last 20.
  • Each interface has an ERC-165 ID, for example 0xcde244d9 for ERC-721 top-down.

Sample code

Putting NFT #3 inside composable token #6, then reading the root owner:

// Attach child: the parent tokenId goes in `data`
ERC721(childContract).safeTransferFrom(msg.sender, composable, 3, abi.encode(uint256(6)));

// Who ultimately owns token 6 (and therefore child #3)?
bytes32 r = ERC998ERC721TopDown(composable).rootOwnerOf(6);
require(bytes4(r) == 0xcd740db5, "not ERC-998");
address owner = address(uint160(uint256(r)));

Things to know

  • This proposal is still a Draft. Its Security Considerations section says "Needs discussion", and the interfaces are written in Solidity 0.4 syntax.
  • ERC-20 composables also rely on ERC-223-style transfer(to, value, data) and tokenFallback, which most ERC-20 tokens do not support. getERC20 is the fallback.
  • Gas grows with tree depth, because ownership checks walk up to the root.
  • Later standards cover similar ground. ERC-6551 gives each NFT its own smart-contract account that can hold any asset, and ERC-7401 defines parent-governed NFT nesting.

#nft #composable #token #draft

Details

Authors
Matt Lockyer <[email protected]>, Nick Mudge <[email protected]>, Jordan Schalm <[email protected]>, sebastian echeverry <[email protected]>, Zainan Victor Zhou (@xinbenlv)
Status
Draft
Type
Standards Track / ERC
Created
2018-07-07
Requires

Machine-readable: Markdown · JSON