ERC-7401 · Final · ERC · 2023-07-26
ERC-7401: Parent-Governed Non-Fungible Tokens Nesting
Lets an ERC-721 NFT own other NFTs, with the parent token's owner fully in control of which children it accepts, keeps or sends away.
What problem does it solve?
Under plain ERC-721 an NFT can be owned by a wallet or a contract, but not by another NFT. That makes common ideas awkward: selling a bundle of NFTs in one transaction, a game character that "holds" its items, a membership pass that receives airdropped perks, or a shipping-container token that collects a soulbound record for each leg of its journey.
ERC-7401 defines a standard way for NFTs to own other NFTs. It supersedes ERC-6059, which had the same design but an interface ID that did not match its published interface; ERC-7401 fixes that and is otherwise functionally equivalent.
How it works
- Parent and child. A token can be both a child (owned by one parent token) and a parent (owning many children). Nesting a token is done like a transfer, but to a
(contract, tokenId)pair vianestTransferFrom. - Root owner.
ownerOfwalks up the tree and returns the first owner that is not an NFT (a wallet or receiver contract).directOwnerOfreturns the immediate owner as(address, parentTokenId, isNft). - Propose, then accept. Anyone can send a child to a parent, but it lands in a pending list (recommended max 128). Only the root owner (or an approved party) can
acceptChildit into the active list, orrejectAllChildren. Nobody can force a token onto you. - Parent-governed. While a token is nested, only its parent can move it. The root owner calls
transferChildon the parent contract, which can unnest the child to a wallet, move it into another parent (where it becomes pending again), reject or abandon it. - Burning.
burn(tokenId, maxRecursiveBurns)also burns children recursively, reverting if more children exist than the limit allows. - Events
NestTransfer,ChildProposed,ChildAccepted,AllChildrenRejectedandChildTransferredlet indexers rebuild the tree.
The ERC-165 interface ID is 0x42b0e56f.
Sample code
Nesting a token into a parent and accepting it (ethers v6):
import { Contract, Wallet, JsonRpcProvider } from "ethers";
const abi = [
"function nestTransferFrom(address from, address to, uint256 tokenId, uint256 destinationId, bytes data)",
"function pendingChildrenOf(uint256 parentId) view returns (tuple(uint256 tokenId, address contractAddress)[])",
"function acceptChild(uint256 parentId, uint256 childIndex, address childAddress, uint256 childId)",
"function directOwnerOf(uint256 tokenId) view returns (address, uint256, bool)",
];
const signer = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));
const items = new Contract(itemsAddr, abi, signer); // child collection
const heroes = new Contract(heroesAddr, abi, signer); // parent collection
// 1. Send item #7 into hero #1 (lands in the hero's pending list)
await (await items.nestTransferFrom(signer.address, heroesAddr, 7n, 1n, "0x")).wait();
// 2. As the hero's root owner, accept it
const pending = await heroes.pendingChildrenOf(1n);
const i = pending.findIndex((c: any) => c.contractAddress === itemsAddr && c.tokenId === 7n);
await (await heroes.acceptChild(1n, i, itemsAddr, 7n)).wait();
console.log(await items.directOwnerOf(7n)); // [heroesAddr, 1n, true]
Things to know
- Status is Final. Use this rather than ERC-6059 for new contracts.
- Token ID
0cannot be used, because0means "not owned by an NFT" indirectOwnerOf. This is the only incompatibility with ERC-721. balanceOfcounts only directly owned tokens, not those nested deeper.- Marketplace risk: a seller can pull children out of a listed parent just before a sale. Marketplaces should verify the expected children at settlement.
- Related standards from the same ecosystem cover multiple assets per token (ERC-5773) and on-chain attributes (ERC-7508).