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 explores ERC7401, a proposal addressing issues with ERC6059, the standard for nesting one NFT within another.

The following explanation translates, summarizes, and expands on the specification linked below.

As of September 12, 2023, ERC7401 is in the Last Call stage.

Overview

ERC7401 is a standard replacing ERC6059. It extends ERC721 to manage parent-child relationships between NFTs (non-fungible tokens).

See the following article for more about ERC6059.

[ERC6059] Understanding nested structures across multiple NFT collections

The basic idea behind the proposal is as follows.

An NFT can be owned not only by an externally owned account (EOA) or a smart contract, but also by another NFT. In other words, NFTs themselves can own other NFTs.

Nesting one NFT within another works in much the same way as transferring an NFT to another user. However, transferring a child NFT from its parent requires a transaction initiated by the account that owns the parent NFT.

An NFT can be owned by another NFT, and one NFT can also own multiple NFTs. The proposal provides a framework for establishing parent-child relationships between NFTs. A parent NFT is a token that owns other NFTs, while a child NFT is a token owned by another NFT. A single token can be both a parent and a child. Child NFTs are fully controlled by the parent NFT's owner, but anyone can propose a new relationship.

The standard enables more flexible management of NFT ownership and relationships and is intended to contribute to the development of the NFT ecosystem.

The figures are reproduced from the original Japanese article; any Japanese labels are retained.

Nestable tokens and their parent-child relationships

The diagram shows a token that is both a parent and a child.

This token owns other tokens and is itself owned by another token. The owner of the parent token has ultimate authority over all child tokens and their associated tokens and can manage them freely. This mechanism allows highly flexible NFT ownership structures and represents complex ownership relationships effectively.

Motivation

NFTs (non-fungible tokens) are widely used throughout the Ethereum ecosystem for a variety of purposes. This has created a need to define additional NFT functionality through a common standard. Allowing tokens to own other tokens is an important capability that can improve their utility, usability, and forward compatibility.

Four years after the initial introduction of ERC721, various requirements and needs for NFTs have emerged. This ERC improves ERC721 in the following four areas.

  • Bundling
    • Functionality for managing tokens together.
  • Collecting
    • Functionality for collecting tokens.
  • Membership
    • Functionality allowing tokens to belong to a particular group or community.
  • Delegation
    • Functionality for delegating ownership or token functionality to other users.

The proposal also fixes inconsistencies in the ERC6059 interface specification. As ERC6059 progressed through the proposal process, its interface ID became inconsistent with the interface specification. This proposal fixes that discrepancy. Aside from these corrections, the proposal is functionally equivalent to ERC6059.

Bundling

ERC721 is widely used to represent tokens associated with multimedia content. However, bundling NFTs from multiple collections and selling them in a single transaction has not been straightforward. This proposal provides a standardized approach. By combining all tokens into one bundle and selling it, control over every token can be transferred to the buyer in a single transaction.

Collecting

Many NFT collectors collect tokens according to various criteria. Some focus on utility, while others value uniqueness or visual appeal. There was no standardized way to group NFTs associated with a particular account. This proposal introduces functionality for grouping NFTs according to their owner's preferences. A root parent token represents a particular group of tokens, and the child tokens nested within it belong to that group.

The proposal also addresses the emergence of soulbound (non-transferable) tokens. Holding multiple soulbound tokens as children enables various use cases. For example, in a supply-chain use case, an NFT could represent a shipping container, with multiple child tokens representing stages of its journey.

Membership

NFTs can represent membership in decentralized autonomous organizations (DAOs) or private groups. Some organizations issue NFTs to holders of membership NFTs. Nesting tokens within tokens simplifies the issuance process, allowing bonus NFTs to be issued directly to membership NFTs.

Delegation

Voting is one of the main functions of a DAO, and various voting approaches exist. One approach allows members to delegate their voting power to other members. With this proposal, a member can nest a voting NFT within the delegate's NFT when delegating votes and return it to the original owner when the delegation is revoked.

Specification

javascript
/// @title EIP-7401 Parent-Governed Nestable Non-Fungible Tokens
/// @dev See https://eips.ethereum.org/EIPS/eip-7401
/// @dev Note: the ERC-165 identifier for this interface is 0x42b0e56f.

pragma solidity ^0.8.16;

interface IERC7059 /* is ERC165 */ {
    /**
     * @notice The core struct of ownership.
     * @dev The `DirectOwner` struct is used to store information of the next immediate owner, be it the parent token,
     * an `ERC721Receiver` contract or an externally owned account.
     * @dev If the token is not owned by an NFT, the `tokenId` MUST equal `0`.
     * @param tokenId ID of the parent token
     * @param ownerAddress Address of the owner of the token. If the owner is another token, then the address MUST be
     *  the one of the parent token's collection smart contract. If the owner is externally owned account, the address
     *  MUST be the address of this account
     */
    struct DirectOwner {
        uint256 tokenId;
        address ownerAddress;
    }

    /**
     * @notice The core child token struct, holding the information about the child tokens.
     * @return tokenId ID of the child token in the child token's collection smart contract
     * @return contractAddress Address of the child token's smart contract
     */
    struct Child {
        uint256 tokenId;
        address contractAddress;
    }

    /**
     * @notice Used to notify listeners that the token is being transferred.
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     * @param from Address of the previous immediate owner, which is a smart contract if the token was nested.
     * @param to Address of the new immediate owner, which is a smart contract if the token is being nested.
     * @param fromTokenId ID of the previous parent token. If the token was not nested before, the value MUST be `0`
     * @param toTokenId ID of the new parent token. If the token is not being nested, the value MUST be `0`
     * @param tokenId ID of the token being transferred
     */
    event NestTransfer(
        address indexed from,
        address indexed to,
        uint256 fromTokenId,
        uint256 toTokenId,
        uint256 indexed tokenId
    );

    /**
     * @notice Used to notify listeners that a new token has been added to a given token's pending children array.
     * @dev Emitted when a child NFT is added to a token's pending array.
     * @param tokenId ID of the token that received a new pending child token
     * @param childIndex Index of the proposed child token in the parent token's pending children array
     * @param childAddress Address of the proposed child token's collection smart contract
     * @param childId ID of the child token in the child token's collection smart contract
     */
    event ChildProposed(
        uint256 indexed tokenId,
        uint256 childIndex,
        address indexed childAddress,
        uint256 indexed childId
    );

    /**
     * @notice Used to notify listeners that a new child token was accepted by the parent token.
     * @dev Emitted when a parent token accepts a token from its pending array, migrating it to the active array.
     * @param tokenId ID of the token that accepted a new child token
     * @param childIndex Index of the newly accepted child token in the parent token's active children array
     * @param childAddress Address of the child token's collection smart contract
     * @param childId ID of the child token in the child token's collection smart contract
     */
    event ChildAccepted(
        uint256 indexed tokenId,
        uint256 childIndex,
        address indexed childAddress,
        uint256 indexed childId
    );

    /**
     * @notice Used to notify listeners that all pending child tokens of a given token have been rejected.
     * @dev Emitted when a token removes all a child tokens from its pending array.
     * @param tokenId ID of the token that rejected all of the pending children
     */
    event AllChildrenRejected(uint256 indexed tokenId);

    /**
     * @notice Used to notify listeners a child token has been transferred from parent token.
     * @dev Emitted when a token transfers a child from itself, transferring ownership.
     * @param tokenId ID of the token that transferred a child token
     * @param childIndex Index of a child in the array from which it is being transferred
     * @param childAddress Address of the child token's collection smart contract
     * @param childId ID of the child token in the child token's collection smart contract
     * @param fromPending A boolean value signifying whether the token was in the pending child tokens array (`true`) or
     *  in the active child tokens array (`false`)
     * @param toZero A boolean value signifying whether the token is being transferred to the `0x0` address (`true`) or
     *  not (`false`)
     */
    event ChildTransferred(
        uint256 indexed tokenId,
        uint256 childIndex,
        address indexed childAddress,
        uint256 indexed childId,
        bool fromPending,
        bool toZero
    );

    /**
     * @notice Used to retrieve the *root* owner of a given token.
     * @dev The *root* owner of the token is the top-level owner in the hierarchy which is not an NFT.
     * @dev If the token is owned by another NFT, it MUST recursively look up the parent's root owner.
     * @param tokenId ID of the token for which the *root* owner has been retrieved
     * @return owner The *root* owner of the token
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @notice Used to retrieve the immediate owner of the given token.
     * @dev If the immediate owner is another token, the address returned, MUST be the one of the parent token's
     *  collection smart contract.
     * @param tokenId ID of the token for which the direct owner is being retrieved
     * @return address Address of the given token's owner
     * @return uint256 The ID of the parent token. MUST be `0` if the owner is not an NFT
     * @return bool The boolean value signifying whether the owner is an NFT or not
     */
    function directOwnerOf(uint256 tokenId)
        external
        view
        returns (
            address,
            uint256,
            bool
        );

    /**
     * @notice Used to burn a given token.
     * @dev When a token is burned, all of its child tokens are recursively burned as well.
     * @dev When specifying the maximum recursive burns, the execution MUST be reverted if there are more children to be
     *  burned.
     * @dev Setting the `maxRecursiveBurn` value to 0 SHOULD only attempt to burn the specified token and MUST revert if
     *  there are any child tokens present.
     * @param tokenId ID of the token to burn
     * @param maxRecursiveBurns Maximum number of tokens to recursively burn
     * @return uint256 Number of recursively burned children
     */
    function burn(uint256 tokenId, uint256 maxRecursiveBurns)
        external
        returns (uint256);

    /**
     * @notice Used to add a child token to a given parent token.
     * @dev This adds the child token into the given parent token's pending child tokens array.
     * @dev The destination token MUST NOT be a child token of the token being transferred or one of its downstream
     *  child tokens.
     * @dev This method MUST NOT be called directly. It MUST only be called from an instance of `IERC7059` as part of a 
        `nestTransfer` or `transferChild` to an NFT.
     * @dev Requirements:
     *
     *  - `directOwnerOf` on the child contract MUST resolve to the called contract.
     *  - the pending array of the parent contract MUST not be full.
     * @param parentId ID of the parent token to receive the new child token
     * @param childId ID of the new proposed child token
     */
    function addChild(uint256 parentId, uint256 childId) external;

    /**
     * @notice Used to accept a pending child token for a given parent token.
     * @dev This moves the child token from parent token's pending child tokens array into the active child tokens
     *  array.
     * @param parentId ID of the parent token for which the child token is being accepted
     * @param childIndex Index of the child token to accept in the pending children array of a given token
     * @param childAddress Address of the collection smart contract of the child token expected to be at the specified
     *  index
     * @param childId ID of the child token expected to be located at the specified index
     */
    function acceptChild(
        uint256 parentId,
        uint256 childIndex,
        address childAddress,
        uint256 childId
    ) external;

    /**
     * @notice Used to reject all pending children of a given parent token.
     * @dev Removes the children from the pending array mapping.
     * @dev The children's ownership structures are not updated.
     * @dev Requirements:
     *
     * - `parentId` MUST exist
     * @param parentId ID of the parent token for which to reject all of the pending tokens
     * @param maxRejections Maximum number of expected children to reject, used to prevent from
     *  rejecting children which arrive just before this operation.
     */
    function rejectAllChildren(uint256 parentId, uint256 maxRejections) external;

    /**
     * @notice Used to transfer a child token from a given parent token.
     * @dev MUST remove the child from the parent's active or pending children.
     * @dev When transferring a child token, the owner of the token MUST be set to `to`, or not updated in the event of `to`
     *  being the `0x0` address.
     * @param tokenId ID of the parent token from which the child token is being transferred
     * @param to Address to which to transfer the token to
     * @param destinationId ID of the token to receive this child token (MUST be 0 if the destination is not a token)
     * @param childIndex Index of a token we are transferring, in the array it belongs to (can be either active array or
     *  pending array)
     * @param childAddress Address of the child token's collection smart contract
     * @param childId ID of the child token in its own collection smart contract
     * @param isPending A boolean value indicating whether the child token being transferred is in the pending array of the
     *  parent token (`true`) or in the active array (`false`)
     * @param data Additional data with no specified format, sent in call to `to`
     */
    function transferChild(
        uint256 tokenId,
        address to,
        uint256 destinationId,
        uint256 childIndex,
        address childAddress,
        uint256 childId,
        bool isPending,
        bytes data
    ) external;

    /**
     * @notice Used to retrieve the active child tokens of a given parent token.
     * @dev Returns array of Child structs existing for parent token.
     * @dev The Child struct consists of the following values:
     *  [
     *      tokenId,
     *      contractAddress
     *  ]
     * @param parentId ID of the parent token for which to retrieve the active child tokens
     * @return struct[] An array of Child structs containing the parent token's active child tokens
     */
    function childrenOf(uint256 parentId)
        external
        view
        returns (Child[] memory);

    /**
     * @notice Used to retrieve the pending child tokens of a given parent token.
     * @dev Returns array of pending Child structs existing for given parent.
     * @dev The Child struct consists of the following values:
     *  [
     *      tokenId,
     *      contractAddress
     *  ]
     * @param parentId ID of the parent token for which to retrieve the pending child tokens
     * @return struct[] An array of Child structs containing the parent token's pending child tokens
     */
    function pendingChildrenOf(uint256 parentId)
        external
        view
        returns (Child[] memory);

    /**
     * @notice Used to retrieve a specific active child token for a given parent token.
     * @dev Returns a single Child struct locating at `index` of parent token's active child tokens array.
     * @dev The Child struct consists of the following values:
     *  [
     *      tokenId,
     *      contractAddress
     *  ]
     * @param parentId ID of the parent token for which the child is being retrieved
     * @param index Index of the child token in the parent token's active child tokens array
     * @return struct A Child struct containing data about the specified child
     */
    function childOf(uint256 parentId, uint256 index)
        external
        view
        returns (Child memory);

    /**
     * @notice Used to retrieve a specific pending child token from a given parent token.
     * @dev Returns a single Child struct locating at `index` of parent token's active child tokens array.
     * @dev The Child struct consists of the following values:
     *  [
     *      tokenId,
     *      contractAddress
     *  ]
     * @param parentId ID of the parent token for which the pending child token is being retrieved
     * @param index Index of the child token in the parent token's pending child tokens array
     * @return struct A Child struct containing data about the specified child
     */
    function pendingChildOf(uint256 parentId, uint256 index)
        external
        view
        returns (Child memory);

    /**
     * @notice Used to transfer the token into another token.
     * @dev The destination token MUST NOT be a child token of the token being transferred or one of its downstream
     *  child tokens.
     * @param from Address of the direct owner of the token to be transferred
     * @param to Address of the receiving token's collection smart contract
     * @param tokenId ID of the token being transferred
     * @param destinationId ID of the token to receive the token being transferred
     * @param data Additional data with no specified format
     */
    function nestTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        uint256 destinationId,
        bytes memory data
    ) external;
}

Token IDs must never be 0. The proposal uses 0 to indicate that the token or destination is not an NFT.

Additional notes

The following questions were considered in designing the proposal.

Why was this name chosen?

The most important aspect of the proposal is that the parent token controls nesting. The child token's role is simply to be nestable and to support the token that owns it. For this reason, the title Parent-Centered was chosen.

Why not automatically accept child tokens using EIP-712 permit-style signatures?

For consistency. This proposal extends ERC721, which already uses a transaction to authorize token operations. Supporting message signatures for this operation alongside the existing mechanism would be inconsistent.

Why use indexes?

To reduce gas consumption. Finding a particular token by its token ID would require iterating through an array, making the operation's cost dependent on the size of the active or pending child array. Using an index makes the cost constant. Because the active and pending child lists must be maintained, methods for retrieving these lists are part of the proposed interface.

To avoid race conditions in which a token's index changes, operations using an index also include the expected token ID and expected collection smart contract, ensuring that the token accessed through the index is the intended one.

An implementation that tracked indexes internally using mappings was attempted, but it increased the minimum cost of accepting a child token by more than 20% and the cost of mint by more than 15%. The proposal concluded that this was unnecessary for the base standard, leaving it as an extension for use cases that can accept higher transaction costs. The provided reference implementation includes several hooks that allow such an extension.

Why limit the pending child array?

The pending child array is not intended as a buffer for accumulating tokens held by the parent token's root owner, nor as a collection of missing tokens to be promoted to active children. It is simply a list of candidate child tokens that needs to be maintained periodically. The pending child array does not need to be unlimited. Bounding the pending child array also helps protect against spam and griefing. Malicious spam tokens can be issued relatively easily and cheaply. Limiting the pending array makes these tokens easier to identify and prevents legitimate tokens from being lost among large quantities of spam.

The design also considers how to prevent legitimate tokens from being accidentally rejected when clearing the pending child array. An argument specifying the maximum number of pending children to reject was therefore added to the call that clears the pending array. This ensures that only the intended number of pending children is rejected and that the array-clearing operation must revert if new tokens are added to the pending array during the process.

Should a token be allowed to nest within one of its children?

The proposal prevents a parent token from being nested in any of its children or descendants. The parent token and all its children are managed by the parent token's root owner. If a token were nested within one of its children, this would create an ownership cycle, making the tokens in that cycle impossible to manage.

Why is there no separate safe nest transfer method?

nestTransfer is always safe. This is because nestTransfer must verify compatibility with IERC7059 at the destination, as stated in the source.

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

The interface permits tokens to be both sent and received. The propose-accept and parent-governed patterns enable safer usage. Backward compatibility is provided only with ERC721, resulting in a simpler interface. The proposal also provides interoperability between different collections: nesting is not limited to a single smart contract and can occur between completely separate NFT collections. It also addresses inconsistencies in the ERC6059 interface ID, interface specification, and reference implementation.

Propose-Commit pattern

When adding a child token to a parent, the Propose-Commit pattern is used to permit limited changes by third parties. Specifically, a child token is initially placed in the pending array and subsequently moved to the active array by the parent token's root owner. The pending child array is limited to a maximum of 128 slots to prevent spam and griefing.

Only the root owner can accept children, giving the root owner full control over the token and preventing others from forcing them to accept child tokens.

Parent Governed pattern

In this pattern, the parent NFT and its root owner are regarded as the true owners of a nested token. Transferring a token to another token transfers its ownership.

This pattern uses the ERC721 ownerOf function to recursively traverse parent tokens in search of the owner. It ultimately finds the root owner. directOwnerOf is also provided to return the token's immediate owner. The method returns the owner's address, the tokenId (0 if the direct owner is not an NFT), and a flag indicating whether the parent is an NFT.

The parent-governed pattern permits the root owner or an approved third party to perform certain operations on child tokens. These include accepting children, rejecting all children, and transferring children.

If a token is owned by another NFT, however, only the parent NFT itself can perform the operations described above. Transfers originate from the parent token; the method calls the appropriate transfer method in the child token's smart contract depending on whether the destination is an NFT. For burning, the token is first transferred to an EOA (externally owned account) and then burned.

These restrictions are introduced because the transferChild method is necessary to remove a child correctly from its parent when transferring it. This maintains consistency within the parent contract.

Child token management

The proposal introduces various features related to managing child tokens. In particular, transferChild is the primary token management function. It enables various operations and state transitions for child tokens. The following are examples of child-token state transitions achievable through transferChild.

  • Reject a child token
    • Reject a child token rather than accepting it.
  • Abandon a child token
    • Abandon ownership and remove the child token from the owner's tracked children.
  • Unnest a child token
    • Detach a child from its parent token, allowing it to exist independently.
  • Transfer a child token to an EOA or ERC721Receiver
    • Transfer a child token to an externally owned account (EOA) or an ERC721Receiver address.
  • Transfer a child token to a new parent token
    • Transfer the child token to another parent token and nest it.

To perform these operations, configure the parameters passed to transferChild appropriately. The parameters of transferChild and their meanings are as follows.

javascript
function transferChild(
    uint256 tokenId,
    address to,
    uint256 destinationId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes data
) external;
  • tokenId
    • Unique identifier of the child token.
  • to
    • Address to which the child token is transferred.
    • This is an EOA or ERC721Receiver address.
  • destinationId
    • Identifier of the new parent token to which the child will be transferred.
  • childIndex
    • Index indicating the child's position within the parent token.
  • childAddress
    • Smart contract address of the child token.
  • childId
    • Unique identifier of the child token.
  • isPending
    • Boolean indicating whether the child token is pending.
  • data
    • Parameter specifying additional data or information.

Configuring these parameters appropriately enables the desired state transition for the child token. For example, to nest the child within a new parent, specify the new parent's identifier in destinationId. Similarly, to transfer a child token to another address, specify the destination address in to.

  1. Reject a child token This operation rejects the child instead of accepting it and removes it from the current parent token's list. The child does not move to a new parent token.

Rejecting a pending child token

  1. Abandon a child token In this operation, the owner abandons ownership of the child token and removes it from the owner's list. The original explanation describes this as allowing the child token to exist independently.

Abandoning a child token

  1. Unnest a child token This operation removes the child from its current parent so that it can exist independently. The nesting relationship is dissolved.

Removing a child token from its parent

  1. Transfer the child token to an EOA or an ERC721Receiver This operation transfers the child token to an externally owned account (EOA) or an ERC721Receiver. The child token moves to a new owner.

Transferring a child token to an externally owned account

  1. Transfer the child token into a new parent token This operation transfers the child token to a new parent token. The child is placed in the new parent's pending array. However, the new parent's root owner must accept the child before it moves into the active array.

Transferring a child token to another token

Backward compatibility

The nestable token standard is designed to maintain compatibility with the ERC721 token standard. This allows existing ERC721 tools and platforms to be used and nestable tokens to interact with other tokens.

The only difference described here is that a nestable token cannot use 0 as its token ID. ERC721 permits 0 as a token ID, but nestable tokens impose this restriction.

The behavior of the ownerOf method used to determine ownership also differs. In ordinary ERC721, ownerOf returns the owner of the specified token; in nestable tokens, ownership is traced recursively. Starting from the parent token, find its owner and repeat this process until the final owner (the root owner) is found. This identifies the correct owner even when a token is nested.

Nestable tokens also provide directOwnerOf to identify the immediate owner. The method returns the token owner's address, the token ID, and a flag indicating whether the parent is an NFT. This information is useful for obtaining more detailed ownership information.

Through these specifications, nestable tokens maintain compatibility with ERC721 while providing their own additional functionality. This allows integration with existing ERC-721 applications and tools and improves the user experience.

Tests

The code is stored in the following GitHub repository.

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

Reference implementation

The code is stored in the following GitHub repository.

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


_MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP

javascript
uint256 private constant _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP = 100;

Overview A variable that limits the maximum depth when checking for cyclic ownership between tokens.

Details

  • A safeguard against cyclic ownership.
  • Prevents an infinite loop if tokens own each other.
  • The variable has the value 100, preventing 100 or more levels of ownership checks.

_balances

javascript
mapping(address => uint256) private _balances;

Overview A mapping tracking the number of tokens held by each owner.

Details

  • Stores the number of tokens owned by each user (address).
  • Each owner's address is the key, and the number of tokens held by the owner is the value.

Parameters

  • address
    • Address of the token owner.
  • uint256
    • Number of tokens held by the owner.

_tokenApprovals

javascript
mapping(uint256 => mapping(address => address)) private _tokenApprovals;

Overview A mapping tracking addresses approved by token owners and managing permissions to transfer tokens.

Details

  • Stores the address approved by the owner for each token ID.
  • The token ID is the key, and the address approved by the owner is the value.
  • The approved address must be valid for token transfers; this information is particularly important when transferring child tokens.

Parameters

  • uint256
    • Unique token identifier (token ID).
  • address
    • Address of the approving party.
  • address
    • Approved address.

_operatorApprovals

javascript
mapping(address => mapping(address => bool)) private _operatorApprovals;

Overview A mapping indicating whether an owner has granted an operator permission to act.

Details

  • Stores whether the owner has granted an operator (external address) permission to act.
  • The owner's address is the key, with the operator address and its authorization status (true or false) stored in the nested mapping.
  • Used when an operator has permission to manipulate tokens on behalf of an owner.

Parameters

  • address
    • Address of the token owner.
  • address
    • Operator address.
  • bool
    • Authorization status (true or false).

_directOwners

javascript
mapping(uint256 => DirectOwner) private _directOwners;

Overview A mapping storing information about the immediate owner of a token.

Details

  • Stores immediate ownership information for each token ID.
  • The token ID is the key and a DirectOwner struct is the value.
  • This information is used to manage the token ownership hierarchy.

Parameters

  • uint256
    • Unique token identifier (token ID).
  • DirectOwner
    • Token's immediate ownership information (struct).

_activeChildren

javascript
mapping(uint256 => Child[]) internal _activeChildren;

Overview A mapping storing information about active children associated with parent tokens.

Details

  • The parent token's ID is the key; information about associated active children (Child structs) is stored in an array.
  • This information is used to manage the children held by the parent token.

Parameters

  • uint256
    • Parent token ID.
  • Child[]
    • Array containing information about associated active children.

_pendingChildren

javascript
mapping(uint256 => Child[]) internal _pendingChildren;

Overview A mapping storing information about pending children associated with parent tokens.

Details

  • The parent token's ID is the key; information about associated pending children (Child structs) is stored in an array.
  • This information is used to manage pending children and move them into the active child array.

Parameters

  • uint256
    • Parent token ID.
  • Child[]
    • Array containing information about associated pending children.

_childIsInActive

javascript
mapping(address => mapping(uint256 => uint256)) internal _childIsInActive;

Overview A mapping tracking whether a child token is active or pending.

Details

  • The child's smart contract address is the key, its token ID is the nested key, and the child token's state (active or pending, represented by 0 or 1 in the original explanation) is stored as the value.
  • This information is used to track whether a child token is associated with an active or pending parent relationship.

Parameters

  • address
    • Smart contract address of the child token.
  • uint256
    • Child token ID.
  • uint256
    • State of the child token (active: 0, pending: 1).

_onlyApprovedOrOwner

javascript
function _onlyApprovedOrOwner(uint256 tokenId) private view {
    if (!_isApprovedOrOwner(_msgSender(), tokenId))
        revert ERC721NotApprovedOrOwner();
}

Overview A modifier that checks whether the caller operating on a token is the owner or has been approved by the owner.

Details

  • Checks whether the caller owns the token associated with the specified token ID or has been approved by its owner.
  • If the caller is neither the owner nor approved, the transaction reverts with ERC721NotApprovedOrOwner.

Parameters

  • uint256
    • Unique identifier (token ID) of the token to check.

onlyApprovedOrOwner

javascript
modifier onlyApprovedOrOwner(uint256 tokenId) {
    _onlyApprovedOrOwner(tokenId);
    _;
}

Overview A modifier that calls _onlyApprovedOrOwner before executing a function to check whether the caller is the token owner or has been approved by the owner.

Details

  • Calls _onlyApprovedOrOwner before executing the function, verifying that the caller is the owner or an approved party.
  • If the caller is neither the owner nor approved, execution stops.
  • If the check succeeds, the function executes.

Parameters

  • uint256
    • Unique identifier (token ID) of the token to check.

_onlyApprovedOrDirectOwner

javascript
function _onlyApprovedOrDirectOwner(uint256 tokenId) private view {
    if (!_isApprovedOrDirectOwner(_msgSender(), tokenId))
        revert NotApprovedOrDirectOwner();
}

Overview A function checking whether the caller address is approved to manage the specified token or directly owns it.

Details

  • Checks whether the caller has permission to manage the token associated with the specified token ID.
  • If the caller is neither the owner nor approved, the transaction reverts with NotApprovedOrDirectOwner.

Arguments

  • tokenId
    • Unique identifier (token ID) of the token to check.

onlyApprovedOrDirectOwner

javascript
modifier onlyApprovedOrDirectOwner(uint256 tokenId) {
    _onlyApprovedOrDirectOwner(tokenId);
    _;
}

Overview A modifier that calls _onlyApprovedOrDirectOwner before executing a function to verify that the caller is the token owner or is approved by the owner.

Details

  • Calls _onlyApprovedOrDirectOwner before executing the function to check that the caller is the owner or approved.
  • If the caller is neither the owner nor approved, execution stops.
  • If the check succeeds, the function executes.

Arguments

  • tokenId
    • Unique identifier (token ID) of the token to check.

supportsInterface

javascript
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
    return
        interfaceId == type(IERC165).interfaceId ||
        interfaceId == type(IERC721).interfaceId ||
        interfaceId == type(IERC7401).interfaceId;
}

Overview A function checking whether a specified interface ID is supported.

Details

  • Returns true for supported ERC165, ERC721, and ERC7401 interface IDs.

Arguments

  • interfaceId
    • Interface ID to check.

Return value

  • bool
    • true if the interface is supported; false otherwise.

balanceOf

javascript
function balanceOf(address owner) public view virtual returns (uint256) {
    if (owner == address(0)) revert ERC721AddressZeroIsNotaValidOwner();
    return _balances[owner];
}

Overview A function returning the number of tokens held by a specified address (owner).

Details

  • If the address is 0x0 (an invalid owner address), an error is raised with ERC721AddressZeroIsNotaValidOwner.

Arguments

  • owner
    • Owner address whose token count is requested.

Return value

  • uint256
    • Number of tokens held by the specified owner.

transferFrom

javascript


function transferFrom(
    address from,
    address to,
    uint256 tokenId
) public virtual onlyApprovedOrDirectOwner(tokenId) {
    _transfer(from, to, tokenId, "");
}

Overview A function allowing the owner or an approved party to transfer a specified token to a specified address.

Details

  • Transfers the token with the specified token ID to an address specified by the owner or an approved party.
  • Uses the _transfer function without providing additional data.

Arguments

  • from
    • Source owner address from which the token is transferred.
  • to
    • Destination address to which the token is transferred.
  • tokenId
    • Unique identifier (token ID) of the transferred token.

safeTransferFrom

javascript
function safeTransferFrom(
    address from,
    address to,
    uint256 tokenId
) public virtual {
    safeTransferFrom(from, to, tokenId, "");
}

Overview A function that safely transfers a specified token to an address chosen by its owner or an approved party.

Details

  • The success of a transfer to a contract depends on whether the recipient implements ERC721Receiver.

Arguments

  • from
    • Source owner address from which the token is transferred.
  • to
    • Destination address to which the token is transferred.
  • tokenId
    • Unique identifier (token ID) of the transferred token.

safeTransferFrom (with additional data)

javascript
function safeTransferFrom(
    address from,
    address to,
    uint256 tokenId,
    bytes memory data
) public virtual onlyApprovedOrDirectOwner(tokenId) {
    _safeTransfer(from, to, tokenId, data);
}

Overview A function that safely transfers a specified token to an address chosen by its owner or an approved party. Additional data is provided.

Details

  • The success of a transfer to a contract depends on whether the recipient implements ERC721Receiver.
  • Additional data can also be sent to the recipient.

Arguments

  • from
    • Source owner address from which the token is transferred.
  • to
    • Destination address to which the token is transferred.
  • tokenId
    • Unique identifier (token ID) of the transferred token.
  • data
    • Additional data sent to the recipient during the token transfer.

nestTransferFrom

javascript
function nestTransferFrom(
    address from,
    address to,
    uint256 tokenId,
    uint256 destinationId,
    bytes memory data
) public virtual onlyApprovedOrDirectOwner(tokenId) {

    _nestTransfer(from, to, tokenId, destinationId, data);
}

Overview A function that transfers a specified token to another token.

Details

  • Transfers the token with the specified token ID to another token.
  • The destination token must not be the transferred token itself or one of its children.
  • Uses _nestTransfer for the transfer and supplies additional data.

Arguments

  • from
    • Source owner address from which the token is transferred.
  • to
    • Smart contract address of the collection containing the recipient token.
  • tokenId
    • Unique identifier (token ID) of the transferred token.
  • destinationId
    • Identifier of the token receiving the transferred token.
  • data
    • Additional data sent to the recipient during the token transfer.

_safeTransfer

javascript
function _safeTransfer(
    address from,
    address to,
    uint256 tokenId,
    bytes memory data
) internal virtual {
    _transfer(from, to, tokenId, data);
    if (!_checkOnERC721Received(from, to, tokenId, data))
        revert ERC721TransferToNonReceiverImplementer();
}

Overview A function that safely transfers a token from from to to.

Details

  • This internal function is equivalent to safeTransferFrom and can be used to implement alternative transfer mechanisms (e.g., signature-based transfers).
  • Ensures the source and destination are not the 0 address.
  • Checks that the token identified by tokenId exists and is owned by from.
  • If to refers to a smart contract, it must implement IERC721Receiver-onERC721Received, which is invoked during a safe transfer.
  • Emits a Transfer event.

Arguments

  • from
    • Address of the current owner's account.
  • to
    • Destination address to which the token is transferred.
  • tokenId
    • Unique identifier (token ID) of the transferred token.
  • data
    • Additional data of unspecified format sent when calling to.

_transfer

javascript
function _transfer(
    address from,
    address to,
    uint256 tokenId,
    bytes memory data
) internal virtual {
    (address immediateOwner, uint256 parentId, ) = directOwnerOf(tokenId);
    if (immediateOwner != from) revert ERC721TransferFromIncorrectOwner();
    if (to == address(0)) revert ERC721TransferToTheZeroAddress();

    _beforeTokenTransfer(from, to, tokenId);
    _beforeNestedTokenTransfer(from, to, parentId, 0, tokenId, data);

    _balances[from] -= 1;
    _updateOwnerAndClearApprovals(tokenId, 0, to);
    _balances[to] += 1;

    emit Transfer(from, to, tokenId);
    emit NestTransfer(from, to, parentId, 0, tokenId);

    _afterTokenTransfer(from, to, tokenId);
    _afterNestedTokenTransfer(from, to, parentId, 0, tokenId, data);
}

Overview A function that transfers a token from from to to.

Details

  • Ensures the source and destination are not the 0 address.
  • Checks that the token identified by tokenId is owned by from.
  • Emits a Transfer event.
  • Unlike transferFrom, it does not impose restrictions on msg.sender.

Arguments

  • from
    • Address of the current owner's account.
  • to
    • Destination address to which the token is transferred.
  • tokenId
    • Unique identifier (token ID) of the transferred token.
  • data
    • Additional data of unspecified format sent when calling to.

_nestTransfer

javascript
function _nestTransfer(
    address from,
    address to,
    uint256 tokenId,
    uint256 destinationId,
    bytes memory data
) internal virtual {
    (address immediateOwner, uint256 parentId, ) = directOwnerOf(tokenId);
    if (immediateOwner != from) revert ERC721TransferFromIncorrectOwner();
    if (to == address(0)) revert ERC721TransferToTheZeroAddress();
    if (to == address(this) && tokenId == destinationId)
        revert NestableTransferToSelf();

    // Destination contract checks:
    // It seems redundant, but otherwise it would revert with no error
    if (!to.isContract()) revert IsNotContract();
    if (!IERC165(to).supportsInterface(type(IERC7401).interfaceId))
        revert NestableTransferToNonNestableImplementer();
    _checkForInheritanceLoop(tokenId, to, destinationId);

    _beforeTokenTransfer(from, to, tokenId);
    _beforeNestedTokenTransfer(
        immediateOwner,
        to,
        parentId,
        destinationId,
        tokenId,
        data
    );
    _balances[from] -= 1;
    _updateOwnerAndClearApprovals(tokenId, destinationId, to);
    _balances[to] += 1;

    // Sending to NFT:
    _sendToNFT(immediateOwner, to, parentId, destinationId, tokenId, data);
}

Overview A function that transfers a token to another token.

Details

  • Ensures the source and destination addresses are not the 0 address.
  • The destination token must not be the transferred token itself or one of its children.
  • Checks that the destination smart contract supports ERC7401.
  • Checks for cyclic ownership and reverts the transaction if a cycle is detected.
  • Emits Transfer and NestTransfer events.

Arguments

  • from
    • Address of the current owner's account.
  • to
    • Smart contract address of the collection containing the recipient token.
  • tokenId
    • Unique identifier (token ID) of the transferred token.
  • destinationId
    • Identifier of the recipient token.
  • data
    • Additional data of unspecified format sent when calling addChild.

_sendToNFT

javascript
function _sendToNFT(
    address from,
    address to,
    uint256 parentId,
    uint256 destinationId,
    uint256 tokenId,
    bytes memory data
) private {
    IERC7401 destContract = IERC7401(to);
    destContract.addChild(destinationId, tokenId, data);

    emit Transfer(from, to, tokenId);
    emit NestTransfer(from, to, parentId, destinationId, tokenId);

    _afterTokenTransfer(from, to, tokenId);
    _afterNestedTokenTransfer(
        from,
        to,
        parentId,
        destinationId,
        tokenId,
        data
    );
}

Overview A function that sends a token to another token.

Details

  • If the token is owned by an externally owned account, parentId must be 0.
  • Emits Transfer and NestTransfer events.

Arguments

  • from
    • Source address.
  • to
    • Collection smart contract address of the recipient token.
  • parentId
    • Identifier of the current parent of the token being sent.
  • destinationId
    • Identifier of the recipient token.
  • tokenId
    • Unique identifier (token ID) of the token being sent.
  • data
    • Additional data of unspecified format sent when calling addChild.

_checkForInheritanceLoop

javascript
function _checkForInheritanceLoop(
    uint256 currentId,
    address targetContract,
    uint256 targetId
) private view {
    for (uint256 i; i < _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP; ) {
        (
            address nextOwner,
            uint256 nextOwnerTokenId,
            bool isNft
        ) = IERC7401(targetContract).directOwnerOf(targetId);
        // If there's a final address, we're good. There's no loop.
        if (!isNft) {
            return;
        }
        // Ff the current nft is an ancestor at some point, there is an inheritance loop
        if (nextOwner == address(this) && nextOwnerTokenId == currentId) {
            revert NestableTransferToDescendant();
        }
        // We reuse the parameters to save some contract size
        targetContract = nextOwner;
        targetId = nextOwnerTokenId;
        unchecked {
            ++i;
        }
    }
    revert NestableTooDeep();
}

Overview A function that checks whether nesting a specified token within another token would create cyclic ownership.

Details

  • A cycle can make tokens impossible to manage, so the transaction reverts if a cycle is detected.
  • The ownership-cycle check is bounded to prevent excessive gas consumption.

Arguments

  • currentId
    • Identifier of the token being nested.
  • targetContract
    • Collection smart contract address of the token receiving the nested token.
  • targetId
    • Identifier of the token receiving the nested token.

Return value

  • None.

_safeMint

javascript
function _safeMint(
    address to,
    uint256 tokenId,
    bytes memory data
) internal virtual {
    _mint(to, tokenId, data);
    if (!_checkOnERC721Received(address(0), to, tokenId, data))
        revert ERC721TransferToNonReceiverImplementer();
}

Overview A function that safely mints a token to a specified address and passes additional data to the contract.

Details

  • Calls _mint to create the token and then checks whether the contract accepts the transfer under the ERC721 protocol.

Arguments

  • to
    • Address to which the token is minted.
  • tokenId
    • ID of the token to mint.
  • data
    • Additional data sent with the token.

_mint

javascript
function _mint(
    address to,
    uint256 tokenId,
    bytes memory data
) internal virtual {
    _innerMint(to, tokenId, 0, data);

    emit Transfer(address(0), to, tokenId);
    emit NestTransfer(address(0), to, 0, 0, tokenId);

    _afterTokenTransfer(address(0), to, tokenId);
    _afterNestedTokenTransfer(address(0), to, 0, 0, tokenId, data);
}

Overview A function that mints a token to a specified address. Using this function is discouraged; _safeMint is recommended whenever possible.

Details

  • Checks that tokenId does not already exist.
  • Checks that to is not the zero address.
  • Emits Transfer and NestTransfer events after minting the token.

Arguments

  • to
    • Address to which the token is minted.
  • tokenId
    • ID of the token to mint.
  • data
    • Additional data sent with the token.

_nestMint

javascript
function _nestMint(
    address to,
    uint256 tokenId,
    uint256 destinationId,
    bytes memory data
) internal virtual {
    // It seems redundant, but otherwise it would revert with no error
    if (!to.isContract()) revert IsNotContract();
    if (!IERC165(to).supportsInterface(type(IERC7401).interfaceId))
        revert MintToNonNestableImplementer();

    _innerMint(to, tokenId, destinationId, data);
    _sendToNFT(address(0), to, 0, destinationId, tokenId, data);
}

Overview A function that mints a child token into a specified parent token.

Details

  • Checks that to is a smart contract.
  • Checks that to supports ERC7401.
  • Calls _innerMint to mint the token and then sends the child to the parent token.

Arguments

  • to
    • Collection smart contract address of the parent token into which the child is minted.
  • tokenId
    • ID of the child token to mint.
  • destinationId
    • ID of the parent token in which the child is placed.
  • data
    • Additional data sent when minting the child token.

_innerMint

javascript
function _innerMint(
    address to,
    uint256 tokenId,
    uint256 destinationId,
    bytes memory data
) private {
    if (to == address(0)) revert ERC721MintToTheZeroAddress();
    if (_exists(tokenId)) revert ERC721TokenAlreadyMinted();
    if (tokenId == uint256(0)) revert IdZeroForbidden();

    _beforeTokenTransfer(address(0), to, tokenId);
    _beforeNestedTokenTransfer(
        address(0),
        to,
        0,
        destinationId,
        tokenId,
        data
    );

    _balances[to] += 1;
    _directOwners[tokenId] = DirectOwner({
        ownerAddress: to,
        tokenId: destinationId
    });
}

Overview A function that mints a token to a specified address.

Details

  • Checks that to is not the zero address.
  • Checks that tokenId does not already exist.
  • Checks that tokenId is nonzero.
  • Emits Transfer and NestTransfer events after minting the token.

Arguments

  • to
    • Address to which the token is minted.
  • tokenId
    • ID of the token to mint.
  • destinationId
    • ID of the parent token of the newly minted token.
  • data
    • Additional data sent when minting the token.

ownerOf

javascript
function ownerOf(
    uint256 tokenId
) public view virtual override(IERC7401, IERC721) returns (address) {
    (address owner, uint256 ownerTokenId, bool isNft) = directOwnerOf(
        tokenId
    );
    if (isNft) {
        owner = IERC7401(owner).ownerOf(ownerTokenId);
    }
    return owner;
}

Overview A function that retrieves the root owner of a specified token.

Details

  • Calls directOwnerOf to obtain the immediate owner of the token, and recursively retrieves the root owner of that NFT if the immediate owner is an NFT.

Arguments

  • tokenId
    • ID of the token whose root owner is requested.

Return value

  • Address of the token's root owner.

directOwnerOf

javascript
function directOwnerOf(
    uint256 tokenId
) public view virtual returns (address, uint256, bool) {
    DirectOwner memory owner = _directOwners[tokenId];
    if (owner.ownerAddress == address(0)) revert ERC721InvalidTokenId();

    return (owner.ownerAddress, owner.tokenId, owner.tokenId != 0);
}

Overview A function that retrieves the immediate owner of a specified token.

Details

  • Retrieves the token's immediate ownership information from the _directOwners mapping and determines whether the owner is an externally owned account.

Arguments

  • tokenId
    • ID of the token whose immediate owner is requested.

Return value

  • Address of the immediate owner, token ID, and a boolean indicating whether the immediate owner is a token.

burn

javascript
function burn(
    uint256 tokenId,
    uint256 maxChildrenBurns
) public virtual onlyApprovedOrDirectOwner(tokenId) returns (uint256) {
    return _burn(tokenId, maxChildrenBurns);
}

Overview

** A function that burns (deletes) a specified token.

Details

  • Uses the onlyApprovedOrDirectOwner modifier to ensure that only the owner or an approved account can call the function.
  • Calls _burn to burn the token and recursively burn its children.
  • Approval information is also cleared when the token is burned.

Arguments

  • tokenId
    • ID of the token to burn.

Return value

  • Number of child tokens burned.

_burn

javascript
function _burn(
    uint256 tokenId,
    uint256 maxChildrenBurns
) internal virtual returns (uint256) {
    (address immediateOwner, uint256 parentId, ) = directOwnerOf(tokenId);
    address rootOwner = ownerOf(tokenId);

    _beforeTokenTransfer(immediateOwner, address(0), tokenId);
    _beforeNestedTokenTransfer(
        immediateOwner,
        address(0),
        parentId,
        0,
        tokenId,
        ""
    );

    _balances[immediateOwner] -= 1;
    _approve(address(0), tokenId);
    _cleanApprovals(tokenId);

    Child[] memory children = childrenOf(tokenId);

    delete _activeChildren[tokenId];
    delete _pendingChildren[tokenId];
    delete _tokenApprovals[tokenId][rootOwner];

    uint256 pendingRecursiveBurns;
    uint256 totalChildBurns;

    uint256 length = children.length; //gas savings
    for (uint256 i; i < length; ) {
        if (totalChildBurns >= maxChildrenBurns)
            revert MaxRecursiveBurnsReached(
                children[i].contractAddress,
                children[i].tokenId
            );
        delete _childIsInActive[children[i].contractAddress][
            children[i].tokenId
        ];
        unchecked {
            // At this point we know pendingRecursiveBurns must be at least 1
            pendingRecursiveBurns = maxChildrenBurns - totalChildBurns;
        }
        // We substract one to the next level to count for the token being burned, then add it again on returns
        // This is to allow the behavior of 0 recursive burns meaning only the current token is deleted.
        totalChildBurns +=
            IERC7401(children[i].contractAddress).burn(
                children[i].tokenId,
                pendingRecursiveBurns - 1
            ) +
            1;
        unchecked {
            ++i;
        }
    }
    // Can't remove before burning child since child will call back to get root owner
    delete _directOwners[tokenId];

    emit Transfer(immediateOwner, address(0), tokenId);
    emit NestTransfer(immediateOwner, address(0), parentId, 0, tokenId);

    _afterTokenTransfer(immediateOwner, address(0), tokenId);
    _afterNestedTokenTransfer(
        immediateOwner,
        address(0),
        parentId,
        0,
        tokenId,
        ""
    );

    return totalChildBurns;
}

Overview A function that burns (deletes) a specified token.

Details

  • Uses directOwnerOf to retrieve the token's immediate ownership information and identify the root owner.
  • Uses the onlyApprovedOrDirectOwner modifier to ensure that only the owner or an approved account can call the function.
  • Child tokens are also burned recursively.
  • When the token is burned, data associated with the token and its children is cleared.
  • Emits Transfer and NestTransfer events.

Arguments

  • tokenId
    • ID of the token to burn.
  • maxChildrenBurns
    • Maximum number of child tokens to burn recursively.

Return value

  • Number of child tokens burned.

approve

javascript
function approve(address to, uint256 tokenId) public virtual {
    address owner = ownerOf(tokenId);
    if (to == owner) revert ERC721ApprovalToCurrentOwner();

    if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender()))
        revert ERC721ApproveCallerIsNotOwnerNorApprovedForAll();

    _approve(to, tokenId);
}

Overview A function that grants another address permission to manage a specified token.

Details

  • Retrieves the token's current owner and raises an error if to is the current owner.
  • Raises an error if the caller is neither the token owner nor approved by the owner.
  • Calls _approve to update approval information.

Arguments

  • to
    • Address to approve.
  • tokenId
    • ID of the token for which approval is granted.

getApproved

javascript
function getApproved(uint256 tokenId) public view virtual returns (address) {
    _requireMinted(tokenId);

    return _tokenApprovals[tokenId][ownerOf(tokenId)];
}

Overview A function that retrieves the approved address for a specified token.

Details

  • Checks that the token exists.
  • Retrieves the approved address associated with the token owner from the _tokenApprovals mapping.

Arguments

  • tokenId
    • ID of the token whose approval information is requested.

Return value

  • Address approved for the token.

setApprovalForAll

javascript
function setApprovalForAll(address operator, bool approved) public virtual {
    if (_msgSender() == operator) revert ERC721ApproveToCaller();
    _operatorApprovals[_msgSender()][operator] = approved;
    emit ApprovalForAll(_msgSender(), operator, approved);
}

Overview A function that grants or revokes a specified operator's permission to manage all tokens.

Details

  • Raises an error if the caller attempts to approve itself.
  • Updates the _operatorApprovals mapping to grant or revoke approval for the operator.
  • Emits an ApprovalForAll event to report the change.

Arguments

  • operator
    • Operator address whose approval status is set or revoked.
  • approved
    • true to grant approval; false to revoke it.

isApprovedForAll

javascript
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
    return _operatorApprovals[owner][operator];
}

Overview A function that checks whether a specified owner has authorized an operator to manage tokens.

Details

  • Checks the relationship between the owner and operator in the _operatorApprovals mapping and returns whether permission has been granted.

Arguments

  • owner
    • Owner address.
  • operator
    • Operator address.

Return value

  • true if permission has been granted; false otherwise.

_approve

javascript
function _approve(address to, uint256 tokenId) internal virtual {
    address owner = ownerOf(tokenId);
    _tokenApprovals[tokenId][owner] = to;
    emit Approval(owner, to, tokenId);
}

Overview A function that updates approval information for a specified token.

Details

  • Retrieves the token owner.
  • Updates the _tokenApprovals mapping to set the new approved address for the token.
  • Emits an Approval event to report the change.

Arguments

  • to
    • New address to approve.
  • tokenId
    • ID of the token whose approval is updated.

_updateOwnerAndClearApprovals

javascript
function _updateOwnerAndClearApprovals(uint256 tokenId, uint256 destinationId, address to) internal {
    _directOwners[tokenId] = DirectOwner({
        ownerAddress: to,
        tokenId: destinationId
    });

    // Clear approval information from the previous owner
    _approve(address(0), tokenId);
    _cleanApprovals(tokenId);
}

Overview A function that updates the token's owner and clears approval information associated with the previous owner.

Details

  • Updates the _directOwners mapping to set the token's new owner and parent token ID.
  • Clears approval information from the previous owner.

Arguments

  • tokenId
    • ID of the token being updated.
  • destinationId
    • ID of the recipient token (set to 0 if the new owner is not a token).
  • to
    • New owner address.

_cleanApprovals

javascript
function _cleanApprovals(uint256 tokenId) internal virtual {}

Overview A function that clears approval information associated with a specified token.

Arguments

  • tokenId
    • ID of the token whose approval information is cleared.

_isApprovedOrOwner

javascript
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
    address owner = ownerOf(tokenId);
    return (spender == owner ||
        isApprovedForAll(owner, spender) ||
        getApproved(tokenId) == spender);
}

Overview A function that checks whether a specified address can manage a token.

Details

  • Returns true if the address is the owner, has operator approval from the owner, or has been approved for the token.

Arguments

  • spender
    • Address whose approval or ownership is checked.
  • tokenId
    • Token ID whose approval or ownership is checked.

Return value

  • true if the address can manage the token; false otherwise.

_isApprovedOrDirectOwner

javascript
function _isApprovedOrDirectOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
    (address owner, uint256 parentId, ) = directOwnerOf(tokenId);
    if (parentId != 0) {
        return (spender == owner);
    }
    return (spender == owner ||
        isApprovedForAll(owner, spender) ||
        getApproved(tokenId) == spender);
}

Overview A function that checks whether a specified address is authorized to manage a token as its immediate owner or an approved party.

Details

  • If the parent is an NFT, only the parent token's contract can operate on the token.
  • Otherwise, returns true if the address is the owner, has operator approval from the owner, or is approved for the token.

Arguments

  • spender
    • Address whose approval or ownership is checked.
  • tokenId
    • Token ID whose approval or ownership is checked.

Return value

  • true if the address can manage the token or is its direct owner; false otherwise.

_requireMinted

javascript
function _requireMinted(uint256 tokenId) internal view virtual {
    if (!_exists(tokenId)) revert ERC721InvalidTokenId();
}

Overview A function that checks whether a specified token has been minted.

Details

  • Uses _exists to check whether the token exists.
  • Raises ERC721InvalidTokenId if the token does not exist.

Arguments

  • tokenId
    • ID of the token whose existence is checked.

_exists

javascript
function _exists(uint256 tokenId) internal view virtual returns (bool) {
    return _directOwners[tokenId].ownerAddress != address(0);
}

Overview A function that checks whether a specified token exists.

Details

  • Retrieves ownership information from the _directOwners mapping and considers the token to exist if its owner address is not 0x0.
  • Returns true if the token exists.

Arguments

  • tokenId
    • ID of the token whose existence is checked.

Return value

  • true if the token exists; false otherwise.

_checkOnERC721Received

javascript
function _checkOnERC721Received(
    address from,
    address to,
    uint256 tokenId,
    bytes memory data
) private returns (bool) {
    if (to.isContract()) {
        try
            IERC721Receiver(to).onERC721Received(
                _msgSender(),
                from,
                tokenId,
                data
            )
        returns (bytes4 retval) {
            return retval == IERC721Receiver.onERC721Received.selector;
        } catch (bytes memory reason) {
            if (reason.length == uint256(0)) {
                revert ERC721TransferToNonReceiverImplementer();
            } else {
                /// @solidity memory-safe-assembly
                assembly {
                    revert(add(32, reason), mload(reason))
                }
            }
        }
    } else {
        return true;
    }
}

Overview A function that invokes onERC721Received from the IERC721Receiver interface when the specified address is a contract.

Details

  • If to is a contract, calls onERC721Received from the IERC721Receiver interface and verifies that the returned value is the expected function selector.
  • Returns true when the call succeeds.
  • If the call fails, checks whether the error data is empty. The original description states that ERC721TransferToNonReceiverImplementer is raised when it is nonempty.
  • If the error data is nonempty, uses assembly to propagate the original error.
  • If to is not a contract, returns true.

Arguments

  • from
    • Address of the token's previous owner.
  • to
    • Address receiving the token.
  • tokenId
    • ID of the transferred token.
  • data
    • Optional data sent with the call.

Return value

  • true if the call returned successfully; false otherwise.

addChild

javascript
function addChild(
    uint256 parentId,
    uint256 childId,
    bytes memory data
) public virtual {
    _requireMinted(parentId);

    address childAddress = _msgSender();
    if (!childAddress.isContract()) revert IsNotContract();

    Child memory child = Child({
        contractAddress: childAddress,
        tokenId: childId
    });

    _beforeAddChild(parentId, childAddress, childId, data);

    uint256 length = pendingChildrenOf(parentId).length;

    if (length < 128) {
        _pendingChildren[parentId].push(child);
    } else {
        revert MaxPendingChildrenReached();
    }

    // Previous length matches the index for the new child
    emit ChildProposed(parentId, length, childAddress, childId);

    _afterAddChild(parentId, childAddress, childId, data);
}

Overview A function that adds a child token to a specified parent token.

Details

  • To add a child to an NFT, use nestTransfer, nestMint, or transferChild.
  • Checks that the parent token owns the specified child token.
  • Checks that the parent token's pending child array contains fewer than 128 entries.
  • Creates child token information and appends it to the parent's pending child array.
  • Reports that a pending child has been added.

Arguments

  • parentId
    • ID of the parent token receiving the new child.
  • childId
    • ID of the new child token to add.
  • data
    • Additional data in the specified format.

acceptChild

javascript
function acceptChild(
    uint256 parentId,
    uint256 childIndex,
    address childAddress,
    uint256 childId
) public virtual onlyApprovedOrOwner(parentId) {
    _acceptChild(parentId, childIndex, childAddress, childId);
}

Overview A function that accepts a pending child for a specified parent token.

Details

  • Checks that the parent token owns the specified child token.
  • Checks that the expected child information matches the actual child information.
  • Checks that the child is not already active.
  • Removes the pending child and adds it to the active children.
  • Reports that the child has been accepted successfully.

Arguments

  • parentId
    • ID of the parent token accepting the child.
  • childIndex
    • Index of the child in the parent's pending child array.
  • childAddress
    • Collection smart contract address of the child token.
  • childId
    • Child token ID within its collection contract.

_acceptChild

javascript
function _acceptChild(
    uint256 parentId,
    uint256 childIndex,
    address childAddress,
    uint256 childId
) internal virtual {
    Child memory child = pendingChildOf(parentId, childIndex);
    _checkExpectedChild(child, childAddress, childId);
    if (_childIsInActive[childAddress][childId] != 0)
        revert ChildAlreadyExists();

    _beforeAcceptChild(parentId, childIndex, childAddress, childId);

    // Remove from pending:
    _removeChildByIndex(_pendingChildren[parentId], childIndex);

    // Add to active:
    _activeChildren[parentId].push(child);
    _childIsInActive[childAddress][childId] = 1; // We use 1 as true

    emit ChildAccepted(parentId, childIndex, childAddress, childId);

    _afterAcceptChild(parentId, childIndex, childAddress, childId);
}

Overview A function that accepts a pending child for a specified parent token. The pending child is moved into the parent's active children.

Details

  • Checks that the expected child information matches the actual child information.
  • Checks that the child is not already active.
  • Removes the pending child and adds it to the active children.
  • Reports that the child has been accepted successfully.

Arguments

  • parentId
    • ID of the parent token accepting the child.
  • childIndex
    • Index of the child in the parent's pending child array.
  • childAddress
    • Collection smart contract address of the child token.
  • childId
    • Child token ID within its collection contract.

rejectAllChildren

javascript
function rejectAllChildren(
    uint256 tokenId,
    uint256 maxRejections
) public virtual onlyApprovedOrOwner(tokenId) {
    _rejectAllChildren(tokenId, maxRejections);
}

Overview A function that rejects all pending children of a specified parent token.

Details

  • Removes child tokens from the pending children mapping.
  • Raises an error if the number of pending children exceeds maxRejections.
  • Deletes all pending children and emits an event reporting the operation.
  • The child tokens' ownership data is not updated. If necessary, ownership can be recovered by the previous parent's rootOwner.

Arguments

  • tokenId
    • ID of the parent token whose pending children are all rejected.
  • maxRejections
    • Maximum number of child tokens expected to be rejected.

_rejectAllChildren

javascript
function _rejectAllChildren(
    uint256 tokenId,
    uint256 maxRejections
) internal virtual {
    if (_pendingChildren[tokenId].length > maxRejections)
        revert UnexpectedNumberOfChildren();

    _beforeRejectAllChildren(tokenId);
    delete _pendingChildren[tokenId];
    emit AllChildrenRejected(tokenId);
    _afterRejectAllChildren(tokenId);
}

Overview A function that rejects all pending children of a specified parent token.

Details

  • Removes child tokens from the pending children mapping.
  • Raises an error if the number of pending children exceeds maxRejections.
  • Deletes all pending children and emits an event reporting the operation.

Arguments

  • tokenId
    • ID of the parent token whose pending children are all rejected.
  • maxRejections
    • Maximum number of child tokens expected to be rejected.

transferChild

javascript
function transferChild(
    uint256 tokenId,
    address to,
    uint256 destinationId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes memory data
) public virtual onlyApprovedOrOwner(tokenId)

Overview A function that transfers a child token from a specified parent token.

Details

  • The child is transferred to another address and associated with a new parent if necessary.
  • Checks that the parent token owns the specified child token.
  • Processes the transfer according to whether the child is pending or active.
  • Emits the relevant event if the transfer succeeds.

Arguments

  • tokenId
    • ID of the parent token transferring the child.
  • to
    • Destination address of the child token.
  • destinationId
    • ID of the token receiving the child (set to 0 if the destination is not a token).
  • childIndex
    • Index of the child to transfer within the parent.
  • childAddress
    • Collection smart contract address of the child token.
  • childId
    • Child token ID within its collection contract.
  • isPending
    • Boolean indicating whether the child token is pending.
  • data
    • Additional data in the specified format.

transferChild

javascript
function transferChild(
    uint256 tokenId,
    address to,
    uint256 destinationId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes memory data
) public virtual onlyApprovedOrOwner(tokenId) {
    _transferChild(
        tokenId,
        to,
        destinationId,
        childIndex,
        childAddress,
        childId,
        isPending,
        data
    );
}

Overview A function that transfers a child token from a specified parent token.

Details

  • The child is transferred to another address and associated with a new parent if necessary.
  • Checks that the parent token owns the specified child token.
  • Processes the transfer according to whether the child is pending or active.
  • Emits the relevant event if the transfer succeeds.

Arguments

  • tokenId: ID of the parent token transferring the child.
  • to
    • Destination address of the child token.
  • destinationId
    • ID of the token receiving the child (set to 0 if the destination is not a token).
  • childIndex
    • Index of the child to transfer within the parent.
  • childAddress
    • Collection smart contract address of the child token.
  • childId
    • Child token ID within its collection contract.
  • isPending
    • Boolean indicating whether the child token is pending.
  • data
    • Additional data in the specified format.

Return value

  • None.

_transferChild

javascript
function _transferChild(
    uint256 tokenId,
    address to,
    uint256 destinationId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes memory data
) internal virtual {
    Child memory child;
    if (isPending) {
        child = pendingChildOf(tokenId, childIndex);
    } else {
        child = childOf(tokenId, childIndex);
    }
    _checkExpectedChild(child, childAddress, childId);

    _beforeTransferChild(
        tokenId,
        childIndex,
        childAddress,
        childId,
        isPending,
        data
    );

    if (isPending) {
        _removeChildByIndex(_pendingChildren[tokenId], childIndex);
    } else {
        delete _childIsInActive[childAddress][childId];
        _removeChildByIndex(_activeChildren[tokenId], childIndex);
    }

    if (to != address(0)) {
        if (destinationId == uint256(0)) {
            IERC721(childAddress).safeTransferFrom(
                address(this),
                to,
                childId,
                data
            );
       

 } else {
            // Destination is an NFT
            IERC7401(child.contractAddress).nestTransferFrom(
                address(this),
                to,
                child.tokenId,
                destinationId,
                data
            );
        }
    }

    emit ChildTransferred(
        tokenId,
        childIndex,
        childAddress,
        childId,
        isPending,
        to == address(0)
    );
    _afterTransferChild(
        tokenId,
        childIndex,
        childAddress,
        childId,
        isPending,
        data
    );
}

Overview A function that transfers a child token from a specified parent token.

Details

  • The child is transferred to another address and associated with a new parent if necessary.
  • Checks that the child's address and ID match the expected values.
  • Delegates processing before the transfer to _beforeTransferChild.
  • Removes the child from the pending or active list according to isPending.
  • Transfers the child if the destination to is not 0x0.
  • Emits the relevant event if the transfer succeeds.

Arguments

  • tokenId
    • ID of the parent token transferring the child.
  • to
    • Destination address of the child token.
  • destinationId
    • ID of the token receiving the child (set to 0 if the destination is not a token).
  • childIndex
    • Index of the child to transfer within the parent.
  • childAddress
    • Collection smart contract address of the child token.
  • childId
    • Child token ID within its collection contract.
  • isPending
    • Boolean indicating whether the child token is pending.
  • data
    • Additional data in the specified format.

_checkExpectedChild

javascript
function _checkExpectedChild(
    Child memory child,
    address expectedAddress,
    uint256 expectedId
) private pure {
    if (
        expectedAddress != child.contractAddress ||
        expectedId != child.tokenId
    ) revert UnexpectedChildId();
}

Overview A function that checks whether the child token being accessed is the intended one.

Details

  • Raises UnexpectedChildId if the information in the Child struct does not match the expected address and ID.
  • The Child struct consists of two values, tokenId and contractAddress.

Arguments

  • child
    • Child struct of the child token being accessed.
  • expectedAddress
    • Expected child token address.
  • expectedId
    • Expected child token ID.

childrenOf

javascript
function childrenOf(
    uint256 parentId
) public view virtual returns (Child[] memory) {
    Child[] memory children = _activeChildren[parentId];
    return children;
}

Overview A function that retrieves the active children of a specified parent token.

Details

  • The Child struct consists of two values, tokenId and contractAddress.

Arguments

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

Return value

  • Array of Child structs
    • Array of Child structs containing the parent's active children.

pendingChildrenOf

javascript
function pendingChildrenOf(
    uint256 parentId
) public view virtual returns (Child[] memory) {
    Child[] memory pendingChildren = _pendingChildren[parentId];
    return pendingChildren;
}

Overview A function that retrieves the pending children of a specified parent token.

Details

  • Returns an array of Child structs containing the parent's pending children.
  • The Child struct consists of two values, tokenId and contractAddress.

Arguments

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

Return value

  • Array of Child structs
    • Array of Child structs containing the parent's pending children.

childOf

javascript
function childOf(
    uint256 parentId,
    uint256 index
) public view virtual returns (Child memory) {
    if (childrenOf(parentId).length <= index)
        revert ChildIndexOutOfRange();
    Child memory child = _activeChildren[parentId][index];
    return child;
}

Overview A function that retrieves a particular active child of a specified parent token.

Details

  • Retrieves the Child struct at the specified index from the array of Child structs containing the parent's active children.
  • A Child struct consists of two values, tokenId and contractAddress.
  • Raises ChildIndexOutOfRange if index falls outside the active child array.

Arguments

  • parentId
    • ID of the parent token holding the active child to retrieve.
  • index
    • Index of the child in the parent's active child array.

Return value

  • Child struct
    • Child struct containing information about the specified child token.

pendingChildOf

javascript
function pendingChildOf(
    uint256 parentId,
    uint256 index
) public view virtual returns (Child memory) {
    if (pendingChildrenOf(parentId).length <= index)
        revert PendingChildIndexOutOfRange();
    Child memory child = _pendingChildren[parentId][index];
    return child;
}

Overview A function that retrieves a particular pending child of a specified parent token.

Details

  • Retrieves the Child struct at the specified index from the array of Child structs containing the parent's pending children.
  • A Child struct consists of two values, tokenId and contractAddress.
  • Raises PendingChildIndexOutOfRange if index falls outside the pending child array.

Arguments

  • parentId
    • ID of the parent token holding the pending child to retrieve.
  • index
    • Index of the child in the parent's pending child array.

Return value

  • Child struct
    • Child struct containing information about the specified child token.

_beforeTokenTransfer

javascript
/**
 * @notice Hook called before any token transfer, including minting and burning.
 * @dev Calling conditions:
 *
 *  - When `from` and `to` are both nonzero, `from`'s `tokenId` is transferred to `to`.
 *  - When `from` is zero, `tokenId` is minted to `to`.
 *  - When `to` is zero, `from`'s `tokenId` is burned.
 *  - `from` and `to` are never both zero.
 *
 *  For more about hooks, see xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
 * @param from Address from which the token is transferred
 * @param to Address to which the token is transferred
 * @param tokenId ID of the transferred token
 */
function _beforeTokenTransfer(
    address from,
    address to,
    uint256 tokenId
) internal virtual {}

Overview A hook called before a token transfer, including minting and burning. It can be used to check and process particular conditions related to a transfer.

Details

  • Called before a token is transferred from from to to.
  • Allows minting, burning, and transfer processing to be customized according to the calling conditions.
  • from and to are never both zero.

Arguments

  • from: Address from which the token is transferred
  • to: Address to which the token is transferred
  • tokenId: ID of the transferred token

_afterTokenTransfer

javascript
function _afterTokenTransfer(
    address from,
    address to,
    uint256 tokenId
) internal virtual {}

Overview A hook called after a token transfer, including minting and burning. Can be used to customize processing after a token transfer.

Details

  • Called after a token has been transferred from from to to.
  • Allows post-transfer processing to be customized according to the calling conditions.
  • from and to are never both zero.

Arguments

  • from
    • Address from which the token was transferred.
  • to
    • Address to which the token was transferred.
  • tokenId
    • ID of the transferred token.

_beforeNestedTokenTransfer

javascript
function _beforeNestedTokenTransfer(
    address from,
    address to,
    uint256 fromTokenId,
    uint256 toTokenId,
    uint256 tokenId,
    bytes memory data
) internal virtual {}

Overview A hook called before a nested token transfer (transferring a child token to a parent token). Can be used to customize particular processing before a nested transfer.

Details

  • Called before a nested token transfer (transferring a child token to a parent token).
  • Can be used to customize processing before a nested transfer.
  • Receives the from and to addresses, source and destination token IDs, transferred token ID, and additional data.

Arguments

  • from
    • Address from which the token is transferred.
  • to
    • Address to which the token is transferred.
  • fromTokenId
    • ID of the source token.
  • toTokenId
    • ID of the destination token.
  • tokenId
    • ID of the transferred token.
  • data
    • Additional data of unspecified format (sent with the addChild call).

_afterNestedTokenTransfer

javascript
function _afterNestedTokenTransfer(
    address from,
    address to,
    uint256 fromTokenId,
    uint256 toTokenId,
    uint256 tokenId,
    bytes memory data
) internal virtual {}

Overview A hook called after a nested token transfer (transferring a child token to a parent token). Can be used to customize particular processing after a nested transfer.

Details

  • Called after a nested token transfer (transferring a child token to a parent token).
  • Can be used to customize processing after a nested transfer.
  • Receives the from and to addresses, source and destination token IDs, transferred token ID, and additional data.

Arguments

  • from
    • Address from which the token was transferred.
  • to
    • Address to which the token was transferred.
  • fromTokenId
    • ID of the source token.
  • toTokenId
    • ID of the destination token.
  • tokenId
    • ID of the transferred token.
  • data
    • Additional data of unspecified format (sent with the addChild call).

_beforeAddChild

javascript
function _beforeAddChild(
    uint256 tokenId,
    address childAddress,
    uint256 childId,
    bytes memory data
) internal virtual {}

Overview A hook called before a new pending child is added to the parent token's pending child array. Can be used to customize particular processing before adding a pending child.

Details

  • Called before a new pending child is added to the parent token's pending child array.
  • Can be used to customize processing before adding a pending child.
  • Receives tokenId, childAddress, childId, and additional data.

Arguments

  • tokenId
    • ID of the token receiving the new pending child.
  • childAddress
    • Collection smart contract address of the child token expected at the specified index in the specified parent's pending child array.
  • childId
    • ID of the child token expected at the specified index in the specified parent's pending child array.
  • data
    • Additional data of unspecified format.

_afterAddChild

javascript
function _afterAddChild(
    uint256 tokenId,
    address childAddress,
    uint256 childId,
    bytes memory data
) internal virtual {}

Overview A hook called after a new pending child is added to the parent token's pending child array. Can be used to customize particular processing after adding a pending child.

Details

  • Called after a new pending child is added to the parent token's pending child array.
  • Can be used to customize processing after adding a pending child.
  • Receives tokenId, childAddress, childId, and additional data.

Arguments

  • tokenId: ID of the token receiving the new pending child.
  • childAddress
    • Collection smart contract address of the child token expected at the specified index in the specified parent's pending child array.
  • childId
    • ID of the child token expected at the specified index in the specified parent's pending child array.
  • data
    • Additional data of unspecified format.

_beforeAcceptChild

javascript
function _beforeAcceptChild(
    uint256 parentId,
    uint256 childIndex,
    address childAddress,
    uint256 childId
) internal virtual {}

Overview A hook called before the parent token accepts a pending child. Can be used to customize particular processing before accepting a pending child.

Details

  • Called before the parent token accepts a pending child.
  • Can be used to customize processing before accepting a pending child.
  • Receives parentId, childIndex, childAddress, and childId.

Arguments

  • parentId
    • ID of the token accepting the pending child.
  • childIndex
    • Index of the child to accept in the specified parent's pending child array.
  • childAddress
    • Collection smart contract address of the child token expected at the specified index in the specified parent's pending child array.
  • childId
    • ID of the child token expected at the specified index in the specified parent's pending child array.

_afterAcceptChild

javascript
function _afterAcceptChild(
    uint256 parentId,
    uint256 childIndex,
    address childAddress,
    uint256 childId
) internal virtual {}

Overview A hook called after the parent token accepts a pending child. Can be used to customize particular processing after accepting a pending child.

Details

  • Called after the parent token accepts a pending child.
  • Can be used to customize processing after accepting a pending child.
  • Receives parentId, childIndex, childAddress, and childId.

Arguments

  • parentId
    • ID of the token accepting the pending child.
  • childIndex
    • Index of the child to accept in the specified parent's pending child array.
  • childAddress
    • Collection smart contract address of the child token expected at the specified index in the specified parent's pending child array.
  • childId
    • ID of the child token expected at the specified index in the specified parent's pending child array.

_beforeTransferChild

javascript
function _beforeTransferChild(
    uint256 tokenId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes memory data
) internal virtual {}

Overview A hook called before a child token is transferred from a particular parent's child array. Can be used to customize particular processing before transferring a child token.

Details

  • Called before a child token is transferred from a particular parent's child array.
  • Can be used to customize processing before transferring a child token.
  • Receives tokenId, childIndex, childAddress, childId, isPending, and additional data.

Arguments

  • tokenId
    • ID of the token transferring the child.
  • childIndex
    • Index of the child to transfer from the parent's child array.
  • childAddress
    • Collection smart contract address of the child token expected at the specified index in the specified parent's child array.
  • childId
    • ID of the child token expected at the specified index in the parent's child array.
  • isPending
    • Boolean indicating whether the transfer is from the pending (true) or active (false) children.
  • data
    • Additional data of unspecified format.
    • Sent with the addChild call.

_afterTransferChild

javascript
function _afterTransferChild(
    uint256 tokenId,
    uint256 childIndex,
    address childAddress,
    uint256 childId,
    bool isPending,
    bytes memory data
) internal virtual {}

Overview A hook called after a child token is transferred from a particular parent's child array. Can be used to customize particular processing after transferring a child token.

Details

  • Called after a child token is transferred from a particular parent's child array.
  • Can be used to customize processing after transferring a child token.
  • Receives tokenId, childIndex, childAddress, childId, isPending, and additional data.

Arguments

  • tokenId
    • ID of the token from which the child was transferred.
  • childIndex
    • Index of the child transferred from the parent's child array.
  • childAddress
    • Collection smart contract address of the child token expected at the specified index in the specified parent's child array.
  • childId
    • ID of the child token expected at the specified index in the parent's child array.
  • isPending
    • Boolean indicating whether the transfer was from the pending (true) or active (false) children.
  • data
    • Additional data of unspecified format sent with the addChild call.

_beforeRejectAllChildren

javascript
function _beforeRejectAllChildren(uint256 tokenId) internal virtual {}

Overview A hook called before the pending child array of a particular token is cleared. Can be used to customize particular processing before clearing pending children.

Details

  • Called before the pending child array of a particular token is cleared.
  • Can be used to customize processing before clearing pending children.
  • Receives tokenId.

Arguments

  • tokenId
    • ID of the token rejecting all pending children.

_afterRejectAllChildren

javascript
function _afterRejectAllChildren(uint256 tokenId) internal virtual {}

Overview A hook called after the pending child array of a particular token is cleared. Can be used to customize particular processing after clearing pending children.

Details

  • Called after the pending child array of a particular token is cleared.
  • Can be used to customize processing after clearing pending children.
  • Receives tokenId.

Arguments

  • tokenId
    • ID of the token that rejected all pending children.

Security considerations

The same security considerations as ERC721 (the non-fungible token standard) apply to this standard. These include the possibility that hidden logic may be embedded in various smart contract functions, such as burn, add child, and accept child. Implementers of this standard must therefore take appropriate care to ensure security.

The standard is designed so that the current owner of a token can manage it. This gives the owner flexibility but also introduces certain risks. For example, after listing a parent token for sale, a seller may remove its child tokens before the sale takes place. As a result, the buyer might not receive the expected children. Marketplaces using this standard need to provide verification mechanisms or implement measures to address malicious behavior.

The standard also provides balanceOf, which counts the number of tokens directly owned by a specified address. However, it does not count tokens nested within the tokens owned by that address. Accurately counting deeply nested tokens therefore requires a recursive traversal, potentially affecting performance.

References

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

Conclusion

The original article's closing paragraph refers to ERC6372, a proposal for identifying the clock mode used by a contract, although the article itself covers ERC7401. I hope the explanation was useful.

If you have any questions, feel free to contact me through Twitter direct messages using the link below.

Twitter @cardene777

I also publish content through other platforms; feel free to explore the links below.

https://chaldene.net/