ERC-7085 NFT relationship and attribute standard (NFT Relationship Enhancement)

Draft · NFTs & multi-token · created 2023-05-02

A standard that lets NFTs form reference relationships with each other and record quantified attributes on both the relationship and individual NFTs, connecting NFTs like a graph.

Why it is needed

Current NFT standards (ERC-721, ERC-1155) have no way to record relationships between tokens. For example, when a creator makes a derivative NFT based on an original NFT, there is no standardized way to record which original the derivative references or how strong the relationship between the two tokens is. As a result, users trying to build a complex NFT ecosystem interwoven with originals and derivatives must manage relationship information their own way, which becomes harder to manage and less efficient as the ecosystem grows. This proposal tries to solve this by extending ERC-721 and ERC-1155 to define common functions for setting reference relationships and quantified attributes between NFTs. Prior similar proposals only covered ERC-721 and had no way to establish quantified relationships or object attributes, which is also part of the background.

What to implement

In depth

Setting the relationship: setRelationship

setRelationship(_originalID, _derivativeID, _attribute) creates a reference relationship between an original NFT (_originalID) and a derivative NFT (_derivativeID) that references it. _attribute is a quantified attribute of this relationship, defaulting to 1 if not specified. By design, only one reference relationship can exist between two NFTs, a decision made to keep the graph manageable and prevent it from becoming excessively complex and useless. The reference implementation rejects the call with require if the original and derivative IDs are the same, and stores the value in the relationship[originalNFT][derivativeNFT] mapping.

Setting attributes: setAttribute

setAttribute(_id, _name, _value) sets a quantified attribute consisting of a name (_name) and value (_value) on an NFT (_id). To minimize the gas cost of setting attributes, only one attribute can be set per call. The reference implementation contract records values in an attributes store shaped as mapping(uint256 => mapping(bytes32 => bytes32)).

Lookup functions: getRelationship, getAttribute, getAttributeNames

getRelationship(_originalID, _derivativeID) returns the value of the reference relationship between two NFTs as a uint256. getAttribute(_id, _name) returns the value of a specific attribute of an NFT as a bytes32, and getAttributeNames(_id) returns an array of bytes32 containing all attribute names attached to that NFT. All three are view functions, so anyone can call them to read data. The original text's example shows reading the "Color" attribute value of NFT ID 123 via getAttribute, and reading the list of attribute names for NFT ID 456 via getAttributeNames.

ERC-165 interface detection and INFTGraph

The reference implementation implements the ERC-165 standard interface so other contracts or apps can check whether a given contract supports this proposal's functions before interacting with it. The INFTGraph interface inherits IERC165 and declares five functions (setRelationship, setAttribute, getRelationship, getAttribute, getAttributeNames). The NFTGraph contract's supportsInterface checks against type(INFTGraph).interfaceId.

Backward compatibility

This proposal is designed to be fully backward compatible with existing ERC-721 and ERC-1155 contracts and tokens. Existing NFT contracts and tokens continue to behave exactly as before, and the new setRelationship and setAttribute functions can only be used on contracts that explicitly implement this proposal. It is an application-level standard adopted at the contract level, requiring no hard fork.

Proposal status: Draft

This document is a proposal in Draft status, created on May 2, 2023. The original text also notes that the rules should be designed carefully, considering potential downsides such as increased complexity and gas costs. Since the content is still subject to change, it is advisable to check the latest version of the original text before implementation.

Things to watch out for

Original ERC · ← ERCs