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 examines ERC-6220, a standard for composable NFTs that allows an NFT to equip other NFTs.

This article translates, summarizes, and expands on the following proposal, reflecting the original article published on August 16, 2023.

Overview

Composable NFTs utilizing equippable parts extends ERC-721 to allow non-fungible tokens (NFTs) to select and equip parts.

For each NFT instance, a list of parts is selected from a catalog, and the NFT can equip other NFTs in the slots defined by that catalog. The catalog contains the parts from which the NFT is composed.

The proposal introduces two types of parts: slot parts and fixed parts. A slot can accommodate NFTs from other collections, whereas a fixed part is a complete component with its own metadata.

Equipping a part does not create a new token. Instead, it adds another component that can be rendered when the token is retrieved.

Motivation

NFTs are widely used throughout the Ethereum ecosystem across numerous applications. Allowing tokens to equip other tokens and be composed from available parts provides greater utility, usability, and future compatibility.

In the four years following ERC-721's introduction, many extensions were created to provide additional functionality. This proposal improves ERC-721 in four areas.

  1. Composition
  2. Token progression
  3. Merit tracking
  4. Provable digital scarcity

Composing

NFTs can be combined to create larger structures.

Before this proposal, one approach to combining multiple NFTs into a single structure was to check all compatible NFTs associated with an account and use them indiscriminately. This could produce unexpected results when multiple NFTs were intended for the same slot. Another approach was to maintain a custom registry of the parts to be combined, either in a smart contract or an off-chain database.

The proposal establishes a standardized framework for composing NFTs using on-chain information, allowing an individual NFT to select which parts it uses together. This enables extensive customization of the base NFT.

Consider an NFT representing a film. Some components, such as the credits, should remain fixed, while others, such as scenes, could be swapped to represent the original release, an extended edition, or an anniversary edition.

Token progression

NFTs can evolve throughout their existence, acquiring or earning different parts at different stages.

Gaming provides a clear example. An NFT implementing the proposal could represent a character that equips gear acquired through gameplay. Better items become available as the player progresses.

Rather than simply holding numerous NFTs representing collected items, players can unlock equippable parts and decide which items to equip and which to keep unequipped in their inventory, without relying on a centralized intermediary.

Merit tracking

Equippable NFTs can also track achievements.

In an academic context, an equippable NFT could represent a digital portfolio of academic accomplishments. Its owner could equip and display degree certificates, published research, awards, and similar credentials.

Provable Digital Scarcity

Many NFT projects provide only simulated scarcity. Although there may be a limited supply of tokens, their utility, if any, is not necessarily limited in the same way.

For example, a user might log in to 500 different instances of the same game with the same wallet and NFT, equipping the same hat on 500 different avatars simultaneously. This is possible when the visual representation is managed entirely on the client side.

The proposal introduces a mechanism that can prevent a hat from being equipped on another avatar once it has been transferred to and equipped on one avatar. Applications that enforce this equipment state can provide verifiable digital scarcity.

Specification

IERC6220

javascript
pragma solidity ^0.8.16;

import "./IERC5773.sol";

interface IERC6220 is IERC5773 /*, ERC165 */ {
    struct Equipment {
        uint64 assetId;
        uint64 childAssetId;
        uint256 childId;
        address childEquippableAddress;
    }

    struct IntakeEquip {
        uint256 tokenId;
        uint256 childIndex;
        uint64 assetId;
        uint64 slotPartId;
        uint64 childAssetId;
    }

    event ChildAssetEquipped(
        uint256 indexed tokenId,
        uint64 indexed assetId,
        uint64 indexed slotPartId,
        uint256 childId,
        address childAddress,
        uint64 childAssetId
    );

    event ChildAssetUnequipped(
        uint256 indexed tokenId,
        uint64 indexed assetId,
        uint64 indexed slotPartId,
        uint256 childId,
        address childAddress,
        uint64 childAssetId
    );

    event ValidParentEquippableGroupIdSet(
        uint64 indexed equippableGroupId,
        uint64 indexed slotPartId,
        address parentAddress
    );

    function equip(
        IntakeEquip memory data
    ) external;

    function unequip(
        uint256 tokenId,
        uint64 assetId,
        uint64 slotPartId
    ) external;

    function isChildEquipped(
        uint256 tokenId,
        address childAddress,
        uint256 childId
    ) external view returns (bool);

    function canTokenBeEquippedWithAssetIntoSlot(
        address parent,
        uint256 tokenId,
        uint64 assetId,
        uint64 slotId
    ) external view returns (bool);

    function getEquipment(
        uint256 tokenId,
        address targetCatalogAddress,
        uint64 slotPartId
    ) external view returns (Equipment memory);

    function getAssetAndEquippableData(uint256 tokenId, uint64 assetId)
        external
        view
        returns (
            string memory metadataURI,
            uint64 equippableGroupId,
            address catalogAddress,
            uint64[] calldata partIds
        );
}

Equipment

  • Struct

Stores the core data of an equipped component.

  • assetId
    • The ID of the parent asset equipping the child.
  • childAssetId
    • The ID of the child asset used as equipment.
  • childId
    • The token ID of the equipped child.
  • childEquippableAddress
    • The address of the collection to which the child asset belongs.

IntakeEquip

  • Struct

Represents input data for an equip operation. It is used to pass arguments rather than to store equipment state.

  • tokenId
    • The ID of the parent token being managed.
  • childIndex
    • The child's index in the parent token's list of active children.
  • assetId
    • The ID of the asset on which the child will be equipped.
  • slotPartId
    • The part ID of the slot to equip.
  • childAssetId
    • The ID of the child asset to equip.

ChildAssetEquipped

  • Event

Emitted when a child asset is equipped on a parent asset.

  • tokenId
    • The ID of the parent token performing the equip operation.
  • assetId
    • The ID of the parent asset on which the child is equipped.
  • slotPartId
    • The part ID of the slot being equipped.
  • childId
    • The ID of the equipped child token.
  • childAddress
    • The address of the child token's collection.
  • childAssetId
    • The ID of the equipped child asset.

ChildAssetUnequipped

  • Event

Emitted when a child asset is unequipped from a parent asset.

  • tokenId
    • The ID of the parent token performing the unequip operation.
  • assetId
    • The ID of the parent asset from which the child is removed.
  • slotPartId
    • The part ID of the slot being unequipped.
  • childId
    • The ID of the unequipped child token.
  • childAddress
    • The address of the unequipped child's collection.
  • childAssetId
    • The ID of the unequipped child asset.

ValidParentEquippableGroupIdSet

  • Event

Indicates that assets belonging to a specified equippable group can be equipped on a particular parent collection and slot.

  • equippableGroupId
    • The identifier of the equippable group.
  • slotPartId
    • The part ID of the slot associated with the equippable group.
  • parentAddress
    • The address of the parent collection.

equip

  • Function

Equips a child token on a parent token.

The IntakeEquip struct is passed as the argument.

unequip

  • Function

Unequips a child token from a parent token. Calling this function requires ownership of the token or authorization from its current owner.

Arguments

  • tokenId
    • The ID of the parent token from which the child is removed.
  • assetId
    • The ID of the parent asset on which the child token is equipped.
  • slotPartId
    • The part ID of the slot being unequipped.

isChildEquipped

  • Function

Checks whether a specified parent token has equipped a particular child token.

Arguments

  • tokenId
    • The ID of the parent token to check.
  • childAddress
    • The smart contract address of the child token.
  • childId
    • The ID of the child token to check.

Return value

Returns a bool indicating whether the child token is equipped.

canTokenBeEquippedWithAssetIntoSlot

Checks whether a specified token and asset can be equipped in a particular slot of the specified parent collection.

Arguments

  • parent
    • The smart contract address of the parent token.
  • tokenId
    • The ID of the token being considered for equipment.
  • assetId
    • The ID of the asset to equip.
  • slotId
    • The part ID of the target slot.

Return value

Returns a bool indicating whether the specified token and asset can be equipped in the specified slot.

getEquipment

Retrieves the data of an object equipped in a specified slot of a particular token.

Arguments

  • tokenId
    • The ID of the token whose equipment data is requested.
  • targetCatalogAddress
    • The address of the catalog associated with the token's slot part.
  • slotPartId
    • The part ID of the slot whose equipment is being queried.

Return value

Returns an Equipment struct containing information about the equipped object.

getAssetAndEquippableData

Retrieves data associated with a specified token and asset.

Arguments

  • tokenId
    • The ID of the token whose data is requested.
  • assetId
    • The ID of the asset whose data is requested.

Return values

Returns the asset's metadata URI, equippable group ID, catalog address, and an array of part IDs associated with the asset.

The following summarizes the identifiers and addresses used above.

assetId

Identifies an asset. For example, it can identify a particular representation of equipment or a component.

childAssetId

Identifies the child asset selected for equipment on a parent asset. It specifies which asset of the child token is being used as equipment.

childId

Identifies the child token equipped on the parent. This is the child token's token ID, distinct from its asset ID.

childEquippableAddress

The address of the equippable smart contract associated with the child asset. It identifies the collection to which the child token belongs.

slotPartId

Identifies a slot part. A slot provides space for equipping another NFT, and the slot part itself has a unique identifier. This identifier specifies the particular slot.

childAddress

The smart contract address of the child token. It identifies the collection to which the child belongs and is used when equipping a child on a parent asset.

The relationship between assetId and childAssetId

Consider a game in a virtual world.

Sword: assetId is 12345.

Shield: assetId is 67890.

Suppose player A wants to equip the sword on an NFT they own, whose token ID is 9876.

Player A selects the sword (asset ID 12345) as equipment for the NFT. The sword's asset ID identifies the particular sword asset. When that asset is equipped on another NFT, it becomes the child asset referenced by childAssetId.

For this example, suppose the parent NFT also has an asset with ID 9876. Its token ID and asset ID need not actually be equal.

assetId: 9876 (parent NFT's asset ID)

childAssetId: 12345 (sword asset ID)

Thus, assetId identifies the parent asset, and childAssetId identifies the equipped child asset.

Relationship between assetId and childAssetId

The relationship between childAssetId and childId

childAssetId: Identifies the asset of a child token, such as a particular representation of equipment.

childId: Identifies the child token itself. If a parent NFT has multiple children, each child is identified by its collection address and token ID. If there is no child, there is no equipped child token ID.

Consider an example.

Player A wants to equip a sword (childAssetId: 456) and shield (childAssetId: 789) on an NFT with token ID 123.

  • Sword's childAssetId: 456.
  • Shield's childAssetId: 789.
  • Suppose the sword child token has childId 1.
  • Suppose the shield child token has childId 2.

The childId identifies the particular equipped child token; it is not the child's index in the parent.

Summary

Suppose an NFT with token ID 10 in collection A is to be equipped on an NFT in collection B.

The childId is 10, the token ID in collection A. The childAssetId identifies the selected asset of that child token in collection A, rather than an asset in the parent collection B.

Relationship between childId and childAssetId

childEquippableAddress and childAddress

  • childEquippableAddress:
    • Identifies the collection of the equippable child asset.
    • It specifies the smart contract associated with the child being equipped.
    • This information is important when a child NFT is equipped on a parent NFT.
    • For example, it identifies the collection issuing a weapon or accessory selected for equipment.
  • childAddress:
    • The smart contract address of the child token itself.

Consider a fantasy game using NFTs. Players own character NFTs that can equip child NFTs such as weapons and accessories.

Suppose a player wants to equip a weapon on a character NFT. The weapon is issued by a separate smart contract, and that collection's address is stored as childEquippableAddress in the equipment data. Catalog and child-side compatibility checks determine whether weapons from that collection can be equipped.

When the player equips a particular weapon NFT, its collection address is reported as childAddress in the corresponding equipment event.

Both identifiers refer to the child collection in their respective contexts; neither denotes the owner of the child token.

Relationship between childAddress and childEquippableAddress

ICatalog

javascript
pragma solidity ^0.8.16;

interface ICatalog /* is IERC165 */ {
    event AddedPart(
        uint64 indexed partId,
        ItemType indexed itemType,
        uint8 zIndex,
        address[] equippableAddresses,
        string metadataURI
    );

    event AddedEquippables(
        uint64 indexed partId,
        address[] equippableAddresses
    );

    event SetEquippables(uint64 indexed partId, address[] equippableAddresses);

    event SetEquippableToAll(uint64 indexed partId);

    enum ItemType {
        None,
        Slot,
        Fixed
    }

    struct Part {
        ItemType itemType; //1 byte
        uint8 z; //1 byte
        address[] equippable; //n Collections that can be equipped into this slot
        string metadataURI; //n bytes 32+
    }

    struct IntakeStruct {
        uint64 partId;
        Part part;
    }

    function getMetadataURI() external view returns (string memory);

    function getType() external view returns (string memory);

    function checkIsEquippable(uint64 partId, address targetAddress)
        external
        view
        returns (bool);

    function checkIsEquippableToAll(uint64 partId) external view returns (bool);

    function getPart(uint64 partId) external view returns (Part memory);

    function getParts(uint64[] calldata partIds)
        external
        view
        returns (Part[] memory);
}

Part

  • Struct

Stores the basic information about a part.

  • itemType
    • An enum specifying the type of part (None, Slot, or Fixed).
  • z
    • An integer specifying the part's rendering depth.
  • equippable
    • An array of collection addresses whose tokens can be equipped in this part.
  • metadataURI
    • The part's metadata URI.

IntakeStruct

  • Struct

Represents the information needed to add a new Part.

  • partId
    • The ID to assign to the Part.
  • part
    • The Part struct containing the information to be added.

AddedPart

  • Event

Emitted when a new part is added.

  • partId
    • The ID of the newly added part.
  • itemType
    • The type of part (None, Slot, or Fixed).
  • zIndex
    • An integer specifying the part's rendering depth.
  • equippableAddresses
    • An array of collection addresses whose tokens can be equipped in the part.
  • metadataURI
    • The part's metadata URI.

AddedEquippables

  • Event

Indicates that new equippable collection addresses have been added to a specified part.

  • partId
    • The ID of the part receiving the additional equippable addresses.
  • equippableAddresses
    • An array of newly added equippable addresses.

SetEquippables

  • Event

Emitted when the list of equippable addresses for a particular part is replaced by a new list.

  • partId
    • The ID of the part whose equippable addresses are replaced.
  • equippableAddresses
    • The new array of equippable addresses.

SetEquippableToAll

  • Event

Indicates that tokens from any collection address can be equipped in a specified part.

  • partId
    • The ID of the part opened to all addresses.

getMetadataURI

  • Function

Retrieves the metadata URI of the associated catalog.

Return value

Returns a string containing the catalog's base metadata URI.

getType

  • Function

Retrieves the type of the associated catalog, distinct from the individual part's itemType.

Return value

Returns a string describing the catalog type.

checkIsEquippable

  • Function

Checks whether tokens from a specified collection address can be equipped in a particular part.

Arguments

  • partId
    • The ID of the part to check.
  • targetAddress
    • The collection address to check for compatibility with the part.

Return value

Returns a bool indicating whether tokens from the specified address can be equipped in the specified part.

checkIsEquippableToAll

  • Function

Checks whether a particular Part permits equipment from all addresses.

Arguments

  • partId
    • The ID of the Part to check.

Return value

Returns a bool indicating whether the specified part permits equipment from all addresses.

getPart

  • Function

Retrieves information about a Part with a specified ID.

Arguments

  • partId
    • The ID of the Part to retrieve.

Return value

Returns a Part struct containing information about the specified part.

getParts

  • Function

Retrieves information about multiple parts together.

Arguments

  • partIds
    • An array containing the IDs of the Part entries to retrieve.

Return value

Returns an array of Part structs containing information about the specified parts.

Additional considerations

Why use a catalog instead of supporting direct NFT equipping?

If any NFT could be equipped directly on another NFT, the resulting combinations could be unpredictable. A catalog allows compatible parts to be validated in advance so that the expected combinations can be produced.

Another advantage of catalogs is that they allow reusable fixed parts to be defined.

Why does the proposal define two types of parts?

Some parts are shared by all tokens and do not need to be represented by individual NFTs. Such components can be represented as fixed parts. This reduces clutter in the owner's wallet and provides an efficient way to represent recurring assets associated with NFTs.

Slot parts, by contrast, allow NFTs to be equipped. They enable a base NFT to equip tokens from different collections, including unrelated collections whose compatibility has been verified.

The two types of parts support a wide range of applications. Implementers are not required to use both types and can compose their NFTs according to their requirements.

Why is there no method for retrieving all equipped parts?

Retrieving all equipped parts may not be necessary for every implementation. This functionality can be added as an extension, implemented with hooks, or emulated with an indexer.

Adding functionality as an extension

A catalog provides basic functionality. Additional features or operations can be incorporated when an implementation needs to meet particular requirements. This provides flexibility as new needs arise.

Using hooks

A hook (Hook) allows custom code to be inserted at particular points in the operation of a software component. In this context, an implementation can run additional code before or after an operation. This makes it possible to customize existing behavior or incorporate additional operations.

Emulating functionality with an indexer

An indexer (Indexer) organizes data so that particular information can be retrieved or queried efficiently, much like a database. Indexers can be used to efficiently retrieve the relevant information associated with catalogs and equipment, including data with complex structures.

In short, implementations can add functionality, customize operations, and retrieve the resulting data efficiently without requiring every operation to be part of the standard.

Should a catalog support one NFT collection or any number of collections?

Catalogs are designed to be agnostic to particular use cases, so it makes sense to support reuse as broadly as possible.

Sharing a catalog across multiple collections can improve operational efficiency and reduce the gas costs associated with defining fixed and slot parts.

Fixed parts

Fixed parts are defined in the catalog. They have their own metadata and remain unchanged throughout the lifecycle of the NFT's asset. They cannot be replaced through the equip operation.

A fixed part needs to be defined only once and can then be referenced by any number of tokens and collections.

Defining a component once allows it to be reused by multiple tokens.

Consider a virtual pet NFT with features such as eyes and ears. If those features share a common design applicable to all virtual pets, they can be represented as fixed parts.

Once defined, the same parts can be reused across multiple virtual pets.

Slot parts

Slot parts are defined in a catalog. Rather than supplying the metadata of the equipment itself, they support equipping NFTs from selected collections. The equipped tokens have their own metadata.

This enables interchangeable content that the base NFT's owner can control.

Any number of compatible collections can be equipped across any number of tokens. Compatibility with a particular slot can be checked when defining the catalog and then reused, allowing predictable compositions.

Consider the same virtual pet NFT.

The pet has a space on its back where a frill of a particular color or pattern can be equipped. That space is represented by a slot part.

Users can equip different frill NFTs to customize the appearance of their virtual pets.

The slot part represents the space in which the frills can be equipped; the frills themselves are the interchangeable NFT components.

Fixed parts allow the same design to be reused, whereas slot parts provide spaces where other NFTs can be equipped to customize the composition.

Backward compatibility

The equippable token standard is compatible with ERC-721. It was designed to take advantage of the established tooling available for ERC-721 implementations and to remain compatible with existing ERC-721 infrastructure.

Tests

Tests are included in equippableFixedParts.ts and equippableSlotParts.ts.

equippableFixedParts.ts

equippableSlotParts.ts

Reference implementation

Security considerations

The same security considerations as ERC-721 apply. Any function, including burn, add, or accept, may contain additional or hidden logic.

Citation

Bruno Škvorc (@Swader), Cicada (@CicadaNCR), Steven Pineda (@steven2308), Stevan Bogosavljevic (@stevyhacker), Jan Turk (@ThunderDeliverer), "ERC-6220: Composable NFTs utilizing Equippable Parts," Ethereum Improvement Proposals, no. 6220, December 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6220.

Discussion

I find the idea of equipping one NFT on another particularly interesting. It creates many possibilities for collaboration between NFT projects.

In a game, for example, a character could equip items or even equip an NFT from another collection as a pet.

If assembling a party were treated as another kind of equipment operation, players could equip characters they own on a parent NFT to form a four-character party in an RPG.

It is an interesting standard that makes me want to build something with it.

Final thoughts

This article covered ERC-6220, which provides a standard for composable NFTs that can equip other NFTs.

If you have questions, feel free to send me a direct message on Twitter.

Twitter @cardene777