Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article covers ERC6059, a proposal for a nested NFT interface that introduces parent-child relationships between NFTs.

This explanation translates, summarizes, and expands on the following specification.

Overview

The Parent-Governed Nestable NFT standard extends ERC721 to enable relationships and interactions between different NFTs.

The fundamental idea behind this proposal is simple. An NFT is normally owned by an individual wallet or smart contract, but this proposal allows an NFT itself to be an owner.

Nesting an NFT inside another NFT is much like sending an NFT to another user. An account that owns the parent token can submit a transaction to nest one NFT inside another.

An NFT can be owned by a single other NFT. That NFT can itself own multiple other NFTs. The proposal provides a framework for establishing parent-child relationships between NFTs. A parent token owns other tokens, while a child token is owned by another token. A token can be both a parent and a child. The owner of a parent token has full control over its child tokens, but anyone can propose a child token.

eip-6059-nestable-tokens.png

The diagram shows how a child token can also be a parent token. Both are controlled by the owner of the root parent token.

Motivation

Non-fungible tokens (NFTs) are widely used throughout the Ethereum ecosystem for many purposes. The time has come to standardize additional capabilities for these tokens. Allowing tokens to own other tokens gives them greater utility, usability, and future compatibility.

In the four years since ERC721 was introduced, additional functionality has been needed and countless extensions have appeared. This ERC improves on ERC721 in the following areas.

  1. Bundling
  2. Collections
  3. Memberships
  4. Delegation

Bundling

One of the most common uses of ERC721 is distributing multimedia content associated with a token. When selling a bundle of NFTs from different collections, there has been no straightforward way to group them together and handle the sale in a single transaction. This proposal introduces a standardized approach. By grouping all tokens into a simple bundle and selling that bundle, control of every token passes to the buyer in one transaction.

Collections

Many NFT users collect NFTs according to different criteria. Their preferences and goals vary: some seek token utility, others value unique traits, and others look for visual appeal. However, there has been no standard way to group NFTs associated with a particular account. This proposal allows NFTs to be grouped according to the owner's preferences. A parent token can serve as the root of a group, with all related child tokens nested beneath it.

The increasing use of soulbound (non-transferable) tokens makes this proposal more relevant. Soulbound tokens can represent specific characteristics or attributes. For example, a supply chain may use an NFT to represent a shipping container. The NFT can hold multiple child tokens representing the different stages of the container's journey. Nesting a child token for each step, from departure at the origin through arrival at the warehouse and final destination, makes it possible to manage information about each stage. Soulbound tokens can thus allow the token itself to represent a particular process and its progress.

Memberships

Decentralized autonomous organizations (DAOs) and restricted-access groups may issue NFTs representing membership. Holding an NFT that establishes membership in a particular group can grant access to the organization's or group's benefits and privileges.

Consider a project that operates a DAO and requires membership to participate in decision-making. Typically, holding a DAO membership NFT grants privileges such as voting rights and eligibility for rewards.

The proposed Parent-Governed Nestable NFT standard allows NFTs to be nested inside other NFTs. This can link a membership NFT with separate NFTs representing benefits and privileges associated with that membership. For example, a membership NFT can serve as the parent token, with child tokens representing benefits and permissions nested beneath it to make membership privileges visible.

When an organization introduces a new benefit, it can nest an NFT representing that benefit directly into the membership NFT. Acquiring the new benefit then requires only the addition of a new NFT.

Nesting NFTs within tokens can simplify membership and benefit management and make the value of a user's NFT holdings clearer.

Delegation

Voting is an important function within DAOs (decentralized autonomous organizations), and voting mechanisms vary. One approach is for members to hold transferable voting tokens representing their voting rights and delegate them to other members. This allows members to share voting power effectively.

Consider a DAO deciding whether to invest in a new project. DAO members hold voting tokens and can vote individually. Some members may prefer to delegate their voting power to a trusted fellow member to consolidate their decisions.

Under the proposed Parent-Governed Nestable NFT standard, delegated voting can be represented simply through NFT nesting. Each member holds an NFT representing their voting rights and delegates those rights to another member by nesting the NFT within another NFT belonging to the delegate. The nested NFT represents the authority for the delegate to cast a consolidated vote without requiring the delegating member to participate directly in the decision.

To revoke a delegation, a member can similarly remove the NFT from its current parent token and nest it in a new delegate's NFT. This makes it easier for members to change their delegations.

By using token nesting to delegate or change voting rights, members can coordinate their decisions and adopt flexible voting processes.

Specification

javascript
pragma solidity ^0.8.16;

interface IERC6059 /* is ERC165 */ {
    struct DirectOwner {
        uint256 tokenId;
        address ownerAddress;
    }

    event NestTransfer(
        address indexed from,
        address indexed to,
        uint256 fromTokenId,
        uint256 toTokenId,
        uint256 indexed tokenId
    );

    event ChildProposed(
        uint256 indexed tokenId,
        uint256 childIndex,
        address indexed childAddress,
        uint256 indexed childId
    );

    event ChildAccepted(
        uint256 indexed tokenId,
        uint256 childIndex,
        address indexed childAddress,
        uint256 indexed childId
    );

    event AllChildrenRejected(uint256 indexed tokenId);

    event ChildTransferred(
        uint256 indexed tokenId,
        uint256 childIndex,
        address indexed childAddress,
        uint256 indexed childId,
        bool fromPending
    );

    struct Child {
        uint256 tokenId;
        address contractAddress;
    }

    function ownerOf(uint256 tokenId) external view returns (address owner);

    function directOwnerOf(uint256 tokenId)
        external
        view
        returns (
            address,
            uint256,
            bool
        );

    function burn(uint256 tokenId, uint256 maxRecursiveBurns)
        external
        returns (uint256);

    function addChild(uint256 parentId, uint256 childId) external;

    function acceptChild(
        uint256 parentId,
        uint256 childIndex,
        address childAddress,
        uint256 childId
    ) external;

    function rejectAllChildren(uint256 parentId, uint256 maxRejections) external;

    function transferChild(
        uint256 tokenId,
        address to,
        uint256 destinationId,
        uint256 childIndex,
        address childAddress,
        uint256 childId,
        bool isPending,
        bytes data
    ) external;

    function childrenOf(uint256 parentId)
        external
        view
        returns (Child[] memory);

    function pendingChildrenOf(uint256 parentId)
        external
        view
        returns (Child[] memory);

    function childOf(uint256 parentId, uint256 index)
        external
        view
        returns (Child memory);

    function pendingChildOf(uint256 parentId, uint256 index)
        external
        view
        returns (Child memory);

    function nestTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        uint256 destinationId
    ) external;
}

The terms "pending" and "active" appear throughout the following explanation. Pending means that processing is still in progress. Active means that processing has been completed and further operations can be performed.

Structs

DirectOwner

A struct holding important ownership information. It helps describe a token's owner and ownership hierarchy explicitly. If the token is not owned by an NFT, tokenId must be 0.

Properties

  • tokenId
    • ID of the parent token.
  • ownerAddress
    • Address of the current token's owner.

Child

A struct holding information about a child token.

Properties

  • tokenId
    • ID of the child token.
    • Token ID within the child token's contract.
  • contractAddress
    • Address of the child token's smart contract.
    • Used to identify the contract of the collection to which the child token belongs.

Events

NestTransfer

An event emitted when the token's owner changes.

  • from
    • Sender address.
  • to
    • Recipient address.
  • fromTokenId
    • Token ID of the previous parent.
    • 0 if there was no parent token.
  • toTokenId
    • Token ID of the new parent.
    • 0 if there is no parent token.
  • tokenId
    • Token ID of the transferred NFT.

ChildProposed

An event emitted when a new child token is added to the parent token's pending child array.

Pending refers to a state in which the token is awaiting a particular action or operation. Specifically, it refers to conditions such as the following.

  • Token ownership is awaiting approval for transfer.
  • The parent token is awaiting a decision on a proposed child token.

A pending token is in a temporary state because final confirmation or processing has not yet occurred. It remains pending until the other action is completed.

  • tokenId
    • Token ID of the parent.
  • childIndex
    • Index in the parent token's pending child array.
  • childAddress
    • Address of the child token's contract.
  • childId
    • Token ID within the child token's contract.

ChildAccepted

An event emitted when the parent accepts a pending child token and moves it to the active child array.

Active refers to a token in its normal state, where an action or operation has been completed. An active token can participate in ordinary transactions and ownership transfers.

For example, when a parent accepts a proposed child and approves it as an active child token, the child becomes active and operations such as ownership transfer become possible.

  • tokenId
    • Token ID of the parent.
  • childIndex
    • Index in the parent token's active child array.
  • childAddress
    • Address of the child token's contract.
  • childId
    • Token ID within the child token's contract.

Pending versus active In short, pending represents a token awaiting completion of an action, while active represents a normal state in which ownership transfers and other operations can occur.

AllChildrenRejected

An event emitted when the parent token rejects all pending child tokens.

  • tokenId
    • ID of the parent token whose pending children were rejected.

ChildTransferred

An event emitted when the parent token transfers a child token and ownership is transferred.

  • tokenId
    • Token ID of the parent.
  • childIndex
    • Index of the transferred child in the parent's child array.
  • childAddress
    • Address of the transferred child token's contract.
  • childId
    • Token ID within the child token's contract.
  • fromPending
    • If true, the child was transferred from the pending child array.
    • If false, the child was transferred from the active child array.

Functions

ownerOf

Retrieves the root owner address of the specified token.

Parameters

  • tokenId
    • ID of the token whose root owner is being queried.

Return value

The address of the token's root owner.

directOwnerOf

Retrieves the immediate owner address of the specified token.

Parameters

  • tokenId
    • ID of the token whose immediate owner is being queried.

Return values

  • Address of the token's owner.
  • ID of the parent token.
    • 0 if the owner is not an NFT.
  • A bool indicating whether the owner is an NFT.

burn

Burns the specified token. Associated child tokens are also burned recursively.

Parameters

  • tokenId
    • ID of the token to burn.
  • maxRecursiveBurns
    • Maximum number of recursive burns.

Return value

Number of child tokens burned recursively.

addChild

Adds a child token to a parent token. The child is added to the parent token's pending child array.

Parameters

  • parentId
    • ID of the parent token to which the new child is added.
  • childId
    • Token ID of the proposed child within the child token's contract.

acceptChild

Accepts a pending child token for the parent. The pending child is moved to the active child array.

Parameters

  • parentId
    • ID of the parent token accepting the child.
  • childIndex
    • Index of the child to accept in the pending child array.
  • childAddress
    • Contract address of the child token's collection.
  • childId
    • ID of the child token.

rejectAllChildren

Rejects all pending child tokens of the specified parent.

Parameters

  • parentId
    • ID of the parent token to which the new child is added.
  • childId
    • ID of the parent token whose pending child tokens are to be rejected.
  • maxRejections
    • Maximum number of children expected to be rejected.

transferChild

Transfers a child token from a parent token. The owner of the transferred child token is set to to. If to is the 0x0 address, ownership is not updated.

Parameters

  • tokenId
    • ID of the parent token transferring the child.
  • to
    • Recipient address of the child token.
  • destinationId
    • ID of the destination token accepting the child.
    • 0 if the destination is not a token.
  • childIndex
    • Index of the child token to transfer.
  • childAddress
    • Contract address of the child token's collection.
  • childId
    • ID of the child token.
  • isPending
    • A bool indicating whether the transferred child is in the parent's pending array.
  • data
    • Additional data sent to to.

childrenOf

Retrieves the active child tokens of the specified parent.

Parameters

  • parentId
    • ID of the parent token whose active children are being queried.

Return value

An array of Child structs.

pendingChildrenOf

Retrieves the pending child tokens of the specified parent.

Parameters

  • parentId
    • ID of the parent token whose pending children are being queried.

Return value

An array of Child structs.

childOf

Retrieves the active child token at a specified index for a given parent.

Parameters

  • parentId
    • ID of the parent token whose active child is being queried.
  • index
    • Index of the child token.

Return value

A Child struct.

pendingChildOf

Retrieves the pending child token at a specified index for a given parent.

Parameters

  • parentId
    • ID of the parent token whose pending child is being queried.
  • index
    • Index of the child token.

Return value

A Child struct.

nestTransferFrom

Moves a token into another token. The destination token must not be the token being moved or any of its descendants.

Parameters

  • from
    • Address of the immediate owner of the token being moved.
  • to
    • Address of the destination collection contract.
  • tokenId
    • ID of the token being moved.
  • destinationId
    • ID of the token accepting the moved token.

Ensure that token IDs are not 0. In this proposal, the value 0 indicates that a token or destination is not an NFT.

Specifically, the proposal uses 0 as follows.

  • If the token or destination is not an NFT, its ID is 0.
    • This indicates the absence of a token or destination NFT.
  • If the token or destination is an NFT, its ID is nonzero.
    • This identifies the actual token or destination NFT. An ID of 0 is therefore reserved to indicate a particular condition. It distinguishes whether a token or its destination is an NFT.

Additional considerations

The following questions were considered in designing the proposal.

These questions address the design of the proposal.

1. What should the proposal be called?

The name should accurately communicate the proposal's key characteristics and purpose. The proposal introduces a mechanism in which nesting is controlled by the parent token. The parent token can nest child tokens and support the tokens it owns. Based on this approach, the proposal name includes the idea of being parent-centered. This reflects an essential aspect of the proposal in its title and communicates its purpose and characteristics clearly.

2. Why is automatic acceptance of child tokens using an EIP712 permit-style signature not part of this proposal?

The reason the proposal does not introduce automatic acceptance through an EIP712 permit-style signature is consistency. It extends ERC721, which already uses a transaction for token approvals. Because the proposal already adopts one approach to token transaction operations, introducing a separate signature mechanism could be inconsistent.

Using different signature schemes for different operations would make token operations harder to understand. The proposal therefore consistently uses the existing token approval mechanism to make operations understandable and predictable.

3. Why use indexes?

The proposal uses indexes to reduce gas consumption. For example, accepting or rejecting a particular token uses its array index rather than its token ID. This keeps the operation cost constant regardless of the number of tokens in the array.

Reduced gas consumption is one answer to why indexes are used. Finding a particular token by its ID requires scanning the array one element at a time, so the operation cost grows with the number of active or pending child tokens. With indexes, by contrast, the operation cost remains constant. Although the design requires active and pending child lists to be maintained for each token, the cost of an operation does not grow with list size.

To avoid race conditions when indexes are used, the expected token ID and collection smart contract are included in the operation to verify that the correct token is accessed. An approach that tracked indexes through a mapping was also tested, but it significantly increased the cost of accepting a child token. The proposal notes that such an approach could be implemented as an extension for use cases that accept the additional cost. The sample implementation also provides hooks to adopt this approach.

4. Why limit the pending child array rather than support pagination?

The proposal limits the pending child array for several reasons. The pending child array temporarily holds tokens that the root owner of the parent does not yet intend to promote to active children but still wishes to retain. The pending array is therefore not intended for long-term storage and should be maintained regularly.

Pagination is normally used to divide large amounts of data into smaller pages for display. The pending child array is expected to contain relatively few tokens and does not contain enough data to benefit from pagination. Pagination is therefore unnecessary.

Limiting the pending child array is also intended to protect against spam and abuse. A bounded array makes it more difficult for spam and malicious tokens to enter in addition to legitimate tokens. This reduces the risk of legitimate tokens becoming lost in a flood of spam tokens in the pending child array.

To avoid inadvertently rejecting legitimate tokens when clearing the pending child array, the clear pending child tokens operation includes an argument specifying the maximum number of pending children to reject. This minimizes the risk of rejecting unintended tokens.

5. Should a token be allowed to nest into one of its own child tokens?

The proposal does not allow a token to be nested into one of its own children. This restriction maintains correct token ownership and a valid hierarchy.

For example, suppose there is a parent token A. Token A is controlled by the root owner, and child token B is nested beneath it. If token B were allowed to become the parent of token A through nesting, an ownership cycle would arise between A and B. Token A would own token B while token B simultaneously owned token A.

Such a cycle would complicate token ownership and management and could undermine the consistency of operations and transactions. The proposal therefore prohibits nesting a token into one of its children to preserve a valid hierarchy and ownership structure.

6. Why is there no "safe" nested transfer method?

nestTransfer is always safe. This is because the destination must be checked for IERC6059 compatibility.

7. How does this proposal differ from other proposals addressing similar problems?

It differs from other proposals addressing similar problems in several respects.

First, the proposed interface provides functionality for sending and receiving tokens. This allows tokens to interact, making it easier to move and combine them.

The propose-commit pattern and parent-governed management pattern allow safer usage. Token operations and transfers require particular procedures and permissions and are controlled by authorized users. This helps preserve token security and consistency.

The proposal also emphasizes backward compatibility and provides a concise interface for existing ERC721 tokens. It supports interoperability between different NFT collections, allowing nesting across multiple smart contracts. Different token collections can therefore operate together.

Overall, the proposal takes a distinct approach to token transfers, secure operations, and interoperability between collections.

The propose-commit pattern for child token management

The propose-commit pattern for child token management defines the procedure for adding a new child to a parent token. It allows limited modifications by third parties. The procedure is as follows.

  1. Propose a child token When adding a new child to a parent token, the child first enters the pending state. The pending array therefore contains proposed children that have not yet been committed.

  2. Commit the child token The parent token's root owner moves the proposed child from pending to active. The committed child becomes an active child under the parent's control.

The pending child array is limited to 128 entries to prevent spam and malicious behavior. This helps prevent abuse such as flooding the array with illegitimate tokens.

Restricting child acceptance to the root owner is intended to ensure the reliability of the overall proposal. This guarantees the root owner's full control over the token. Users cannot be forced to accept child tokens against their will.

Parent-governed management pattern

The parent-governed management pattern manages relationships and ownership of nested tokens. Its main elements are described below.

1. Ownership

The parent NFT (parent non-fungible token) and its root owner are the true owners of a nested token. Sending a token into another token relinquishes ownership on the sender's part.

2. Using ownerOf

Based on the ERC721 specification, nested tokens can traverse the ownership hierarchy. A token can thus follow its parents until it finds a non-NFT address, called the root owner.

3. The directOwnerOf method

The proposal also provides the directOwnerOf method. It returns information about the token's immediate owner. This includes the owner's address, a token ID that must be 0 if the immediate owner is not an NFT, and a flag indicating whether the parent is an NFT.

4. Authorized operations

The root owner or an approved party can perform the following operations on child tokens.

  • acceptChild
    • Accept a child token.
  • rejectAllChildren
    • Reject all children.
  • transferChild
    • Transfer a child token.

5. Operations when the owner is not an NFT

If the token is not owned by an NFT, the root owner or an approved party can perform the following operations.

  • transferFrom
    • Transfer the token.
  • safeTransferFrom
    • Safely transfer the token.
  • nestTransferFrom
    • Transfer the token into another token.
  • burn
    • Burn the token.

6. Operations when the owner is an NFT

If a token is owned by an NFT, only the parent NFT itself can perform these operations. Transfers originate from the parent token, making it the entry point for performing the appropriate operations on other tokens.

This restriction ensures that a child token is removed properly from its parent when it is transferred. This prevents inconsistencies in the parent contract.

Child token management

The proposal introduces several child token management functions. In addition to authorizing movement of a child token from the pending array to the active array, the primary management function is transferChild. This function enables the following child token state transitions.

  • Reject a child token
  • Abandon a child token
  • Unnest a child token
  • Transfer a child token to an EOA or ERC721Receiver
  • Transfer a child token to a new parent token

To understand how these state transitions work, consider the parameters available to transferChild:

solidity
function transferChild(
    uint256 tokenId,
    address to,
    uint256 destinationId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes data
) external;

The parameter values must be set according to the desired state transition. Parameters not set in the following examples depend on the child token being managed.

Reject child token

eip-6059-reject-child.png

Abandon child token

eip-6059-abandon-child.png

Unnest child token

eip-6059-unnest-child.png

Transfer the child token to an EOA or an ERC721Receiver

eip-6059-transfer-child-to-eoa.png

Transfer the child token into a new parent token

eip-6059-transfer-child-to-token.png

This state change places the token in the new parent token's pending array. The child still needs to be accepted by the root owner of the new parent. It is then placed in that token's active array.

Backward compatibility

The nestable token standard is designed to be compatible with ERC721. It can therefore use the robust tooling available for ERC721 implementations while maintaining compatibility with existing ERC721 infrastructure.

Tests

The test files are available at the following location.

Source: https://eips.ethereum.org/EIPS/eip-6059

Reference implementation

The reference implementation is available below.

Source: https://eips.ethereum.org/EIPS/eip-6059

Security considerations

The same security considerations as ERC721 apply. Any function, including burning, adding a child, and accepting a child, may contain hidden logic.

Because the current owner is allowed to manage the token, a seller may remove child tokens after listing the parent token for sale but before the sale is completed. The buyer may therefore not receive the expected child tokens. This is a design risk of the standard. Marketplaces need to account for this risk by providing a means of verifying that the expected child tokens are present when the parent is sold or by otherwise mitigating malicious behavior.

References

Bruno Škvorc (@Swader), Cicada (@CicadaNCR), Steven Pineda (@steven2308), Stevan Bogosavljevic (@stevyhacker), Jan Turk (@ThunderDeliverer), "ERC-6059: Parent-Governed Nestable Non-Fungible Tokens," Ethereum Improvement Proposals, no. 6059, November 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6059.

Thoughts

I find this proposal for nesting multiple NFTs particularly interesting.

At first, I thought it might be the same as ERC6150, covered below. A key difference seems to be that NFTs in a parent-child relationship can have different contract addresses.

[ERC6150] Giving NFTs a Hierarchical Structure Like the Linux File System

Managing NFTs across multiple contracts can become chaotic without a clear understanding of the overall structure, but the standard opens up some interesting possibilities.

Conclusion

This article covered ERC6059, a proposal for a nested NFT interface that introduces parent-child relationships between NFTs. I hope it helped clarify the mechanism.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777