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
function setRelationship(uint256 _originalID, uint256 _derivativeID, uint256 _attribute) external;: Sets a reference relationship between an original NFT and a derivative NFT. If no numeric attribute for the relationship is specified, the default value is 1.function setAttribute(uint256 _id, string calldata _name, uint256 _value) external;: Sets a quantified attribute consisting of a name and value on the specified NFT.function getRelationship(uint256 _originalID, uint256 _derivativeID) external view returns (uint256);: Returns the value of the reference relationship between two NFTs as a uint256.function getAttribute(uint256 _id, string calldata _name) external view returns (bytes32);: Returns the value of a specific named attribute set on an NFT as bytes32.function getAttributeNames(uint256 _id) external view returns (bytes32[] memory);: Returns the names of all attributes set on an NFT as a bytes32 array.
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
- Relationship validation: Contracts that implement setRelationship must verify that the relationship being set is valid and has the approval of the relevant parties. Unapproved or malicious relationships can produce unintended consequences.
- Attribute Validation: Contracts that implement setAttribute must carefully validate attributes to block malicious or harmful values. Unvalidated attributes can break the behavior of the NFT ecosystem.
- Access control: Functions that change relationships or attributes in particular must have proper access control restricting who can call them. Unauthorized access can lead to misuse or exploitation.
- Reentrancy Protection: Functions that change relationships or attributes should consider adding reentrancy guards. Otherwise, a reentrancy attack could manipulate the contract's behavior.