EIPs Explained

ERC-6150 · Final · ERC · 2022-12-15

ERC-6150: Hierarchical NFTs

An ERC-721 extension that arranges NFTs in a filesystem-like tree, where each token can have a parent and children, so one contract can model categories, forums or org charts as ownable nodes.

What problem does it solve?

Lots of applications are trees: folders in a filesystem, categories in a shop (Home → Electronics → Video Games), subreddits and posts, departments in a company. Building these on-chain usually means custom data structures with no common interface, so explorers and front ends cannot read them generically.

ERC-6150 standardises a hierarchy of NFTs inside a single ERC-721 contract. Each node in the tree is a token: it can be owned and transferred like any NFT, and its position in the tree can be queried with a small, filesystem-like API. Owning a node could, for example, mean owning a forum category.

How it works

The core interface (ERC-165 ID 0x897e2c73):

Member Purpose
parentOf(tokenId) Parent token ID; 0 for a root
childrenOf(tokenId) Array of child token IDs
isRoot(tokenId) / isLeaf(tokenId) Position checks
Minted(minter, to, parentId, tokenId) Emitted on mint, recording where the node sits

Because parentId == 0 means "root", token ID 0 cannot be a real node; IDs start at 1.

Optional extensions, each with its own ERC-165 ID:

  • Enumerable (0xba541a2e) – childrenCountOf, childOfParentByIndex, indexInChildrenEnumeration for paging through large trees.
  • Burnable (0x4ac0aa46) – safeBurn / safeBatchBurn, which only work on leaf tokens.
  • ParentTransferable (0xfa574808) – transferParent / batchTransferParent to move a node (like mv on a directory), emitting ParentTransferred.
  • AccessControl (0x1d04f0b3) – isAdminOf, canMintChildren, canBurnTokenByAccount for per-node permissions.

Note the difference between owning a node (ERC-721 ownership) and its position (parent/child links); transferring the NFT does not move it in the tree.

Sample code

Walking a tree from the root down (ethers v6):

import { Contract } from "ethers";

const tree = new Contract(treeAddress, [
  "function childrenOf(uint256) view returns (uint256[])",
  "function ownerOf(uint256) view returns (address)",
  "function isLeaf(uint256) view returns (bool)",
], provider);

async function print(id: bigint, depth = 0): Promise<void> {
  const owner = await tree.ownerOf(id);
  console.log(`${"  ".repeat(depth)}#${id} owned by ${owner}`);
  if (await tree.isLeaf(id)) return;
  for (const child of await tree.childrenOf(id)) await print(child, depth + 1);
}

await print(1n); // assuming token 1 is a root

Things to know

  • Status: Final.
  • childrenOf returns an unbounded array. For wide nodes, prefer the Enumerable extension to page through children instead of loading them all on-chain.
  • The spec defines no rules for who may mint children or move nodes; that is left to the implementation or the optional AccessControl extension.
  • Compare ERC-6059, where NFTs (possibly from different collections) are nested and parents control their children, and the older ERC-998 composable tokens. ERC-6150 is about a tree of tokens within one contract.

#nft #erc-721 #hierarchy #tree

Details

Authors
Keegan Lee (@keeganlee), msfew <[email protected]>, Kartin <[email protected]>, qizhou (@qizhou)
Status
Final
Type
Standards Track / ERC
Created
2022-12-15
Requires
Required by

Machine-readable: Markdown · JSON