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.
ERC-7085 proposes a mechanism for managing relationships and attributes associated with ERC-721 and ERC-1155 NFTs.
This article explains the proposal with additional context and examples.
You can find my other EIP articles here.
Overview
The proposed standard builds on existing NFT standards, including ERC-1155, to allow applications to establish relationships between NFTs and assign quantitative attributes to individual tokens.
Rather than treating NFTs solely as isolated assets, the proposal aims to allow multiple NFTs to form an interconnected ecosystem.
Main features
- Defining relationships
- Applications can construct a graph of NFTs that describes how a particular NFT relates to other NFTs.
- Assigning quantitative attributes
- Applications can assign attributes such as weight, value, or durability to individual NFTs.
- This allows NFTs to represent more complex functionality beyond that of simple collectibles.
Benefits and applications
These extensions could be applied to games, virtual real estate, complex digital collections, and other applications.
In a game, for example, players could establish relationships between items or characters and assign particular attributes to them. In a metaverse land application, the value assigned to a plot might be determined partly by its relationships with neighboring plots.
The proposal extends the ways NFTs can be used by supporting richer interactions and more complex ecosystems. It adds capabilities beyond the core ERC-721 and ERC-1155 interfaces.
For more on ERC-721, see the following article.
For more on ERC-1155, see the following article.
Motivation
The proposal extends the functionality of existing NFT standards, ERC-721 and ERC-1155. Specifically, it adds a mechanism for expressing relationships between NFTs and assigning quantitative attributes to those relationships.
Background and limitations
The core ERC-721 and ERC-1155 interfaces do not include a standardized mechanism for directly representing relationships between tokens.
NFTs representing artwork, in-game items, or collectibles can have their own attributes and metadata, but the core standards do not define a common interface for expressing direct relationships or interactions between tokens.
This limitation can complicate the development of interconnected NFT ecosystems. For example, applications that want one NFT to reference or influence another must implement their own mechanisms for managing those relationships.
Objectives of the proposal
The proposal aims to standardize reference relationships and quantitative attributes. NFT developers and users can build more complex relationships between tokens and assign a quantitative value to each relationship, representing concepts such as importance, dependency, or influence.
Potential impact
The extension could support more complex and varied interactions across NFT ecosystems. Possible applications include games, digital art, education, and virtual real estate.
Explicit relationships and attributes could support new forms of storytelling, collections, and interactive experiences.
Challenges to consider
- Increased complexity
- Managing relationships and attributes increases system complexity.
- Developers must implement additional logic to handle these elements correctly.
- Increased gas costs
- Ethereum transactions, including smart contract execution, consume gas.
- Recording relationships and attributes may increase these costs.
- Designing rules
- Applications need clear rules for defining, updating, and removing relationships and attributes.
- Those rules must account for security and privacy considerations.
The proposal opens up additional use cases for NFTs. Realizing them requires addressing implementation complexity, transaction costs, and operational challenges. Careful design and coordination between developers can help address these issues.
Specification
setRelationship
function setRelationship(uint256 _originalID, uint256 _derivativeID, uint256 _attribute) external;Overview
Establishes a reference relationship between an original NFT and a derivative NFT.
Details
The function defines a relationship between the original NFT and a related derivative NFT, with a quantitative attribute attached to that relationship. The default attribute is 1, and callers can also specify it explicitly through the relevant interface.
Parameters
_originalID- ID of the original NFT.
_derivativeID- ID of the derivative NFT that references the original.
_attribute- Quantitative attribute of the relationship.
- Defaults to
1where the interface provides the default form.
setAttribute
function setAttribute(uint256 _id, string calldata _name, uint256 _value) external;Overview
Assigns an attribute to an NFT.
Details
The function associates a named attribute with a value for a specified NFT. Applications can use it to attach particular characteristics or information to the token. Numeric attributes can be represented using the value encoding defined by the application.
Parameters
_id- ID of the NFT whose attribute is being set.
_name- Name of the attribute.
_value- Value of the attribute.
getAttribute
function getAttribute(uint256 _id, string calldata _name) external view returns (bytes32);Overview
Retrieves the value of a particular attribute associated with an NFT.
Details
The function returns the value of the specified attribute for the given NFT, providing an interface for querying token attributes.
Parameters
_id- ID of the NFT whose attribute value is being retrieved.
_name- Name of the attribute to retrieve.
Return value
bytes32- Value of the specified attribute.
getAttributeNames
function getAttributeNames(uint256 _id) external view returns (bytes32[] memory);Overview
Retrieves the names of all attributes associated with an NFT.
Details
The function returns the attribute names registered for the specified NFT, allowing callers to discover which attributes exist.
Parameters
_id- ID of the NFT whose attribute names are being retrieved.
Return value
bytes32[] memory- Array of all attribute names associated with the NFT.
getRelationship
function getRelationship(uint256 _originalID, uint256 _derivativeID) external view returns (uint256);Overview
Retrieves the value of a reference relationship between two NFTs.
Details
The function returns the relationship value associated with an original NFT and a derivative NFT. The relationship must have been established through setRelationship for the returned value to describe a registered relationship.
Parameters
_originalID- ID of the original NFT.
_derivativeID- ID of the derivative NFT referencing the original.
Return value
uint256- Value of the reference relationship between the two NFTs.
Usage example
NFTGraph nftContract = NFTGraph(addressOfContract);
// Retrieve the value of an attribute named "Color" for NFT with ID 123
bytes32 colorValue = nftContract.getAttribute(123, "Color");
// Retrieve the names of all attributes associated with NFT with ID 456
bytes32[] memory attributeNames = nftContract.getAttributeNames(456);The code snippet shows how to retrieve a particular attribute value and obtain all attribute names associated with an NFT. These operations are intended to be used by contracts or applications that work with NFTs.
Code walkthrough
Creating a contract instance
NFTGraph nftContract = NFTGraph(addressOfContract);The code initializes an instance of the existing NFTGraph contract using its deployed address. The variable addressOfContract represents the address of that contract on the blockchain.
Retrieving a particular attribute value
bytes32 colorValue = nftContract.getAttribute(123, "Color");This example retrieves the attribute named "Color" for the NFT with ID 123.
The function returns a bytes32 value, meaning the attribute value is represented using that data type. To obtain a human-readable value such as "Red" or "Blue," callers must interpret the returned bytes according to the encoding used by the application.
Retrieving all associated attribute names
bytes32[] memory attributeNames = nftContract.getAttributeNames(456);This statement retrieves all the attribute names associated with the NFT with ID 456.
The return value is a bytes32[] array. Each attribute name is encoded as bytes32 and must be interpreted using the application's naming convention if a human-readable name is required.
Why these functions matter
Including these functions in a common interface gives developers and users a standardized way to read attributes associated with NFTs.
They provide a basis for managing more complex attributes and relationships in NFT ecosystems, including games, digital art collections, and virtual real estate. This improves the flexibility of NFT integrations and enables developers to explore additional use cases.
Additional considerations
Several design decisions were made when developing the proposal. These decisions are intended to make the NFT extension useful and practical.
Limiting the complexity of NFT relationship graphs
- Design decision
- Limit the relationship graph by allowing only one reference relationship between a pair of NFTs for the relevant relationship key.
- Rationale
- This helps keep the graph manageable and easier for users to understand instead of allowing an unrestricted set of distinct relationships for the same pair.
- The restriction can simplify graph visualization and analysis, allowing developers and users to understand relationships more easily.
Limiting gas costs when setting attributes
- Design decision
- Allow one attribute to be set per attribute-setting call, limiting the amount of work performed by an individual call.
- Rationale
- Ethereum transactions consume gas.
- Updating multiple attributes can increase execution and storage costs, particularly when managing many NFTs.
- Setting one attribute at a time keeps an individual operation smaller. It does not necessarily minimize the total gas required to update many attributes, since batching may amortize some transaction overhead.
Inspiration from graph theory
- Background
- The proposal identifies a lack of comparable standardized functionality and draws inspiration from graph theory, a branch of mathematics.
- Rationale
- Graph theory studies relationships between objects. Applying graph concepts to NFTs enables developers to model interconnected token ecosystems.
- By allowing relationships between NFTs and attaching quantitative attributes to those relationships, the proposal aims to make NFT interfaces more versatile.
These design choices establish a foundation for a practical extension that can benefit NFT creators and users. The proposed functionality could expand the ways NFTs are used and support new applications.
Compatibility
The proposal is designed to remain backward compatible with existing ERC-721 and ERC-1155 contracts and tokens. Existing contracts can continue operating as before even if the proposal is adopted.
The new setRelationship and setAttribute functions are only available on contracts that explicitly implement the extension.
Why backward compatibility matters
- Preserving compatibility
- Existing ERC-721 and ERC-1155 NFTs continue operating without implementing this extension.
- Existing tokens and applications are not required to adopt it.
- Supporting gradual adoption
- Developers who want the new features can implement them in new contracts or update existing contracts where their upgrade architecture permits it.
- Applications can introduce relationship and attribute support without replacing their entire existing system.
Implementing the new features
setRelationship- Establishes a reference relationship between two NFTs.
- Supports new kinds of interaction between NFTs and provides a foundation for more complex token ecosystems.
setAttribute- Assigns a specified attribute to an NFT.
- Allows additional information or characteristics to be associated with the token, broadening its possible applications.
Implementation
ERC-165 interface support
The NFT relationship enhancement contract implements the ERC-165 standard interface for interface detection.
Smart contracts and applications can use it to check whether another contract declares support for the functions defined in the proposal. This is useful for interoperability and selecting the appropriate interaction path, although declaring interface support does not establish that an implementation behaves correctly or securely.
- Reference implementation
- The proposal provides a reference Solidity interface and contract implementing relationship and attribute functionality.
- Developers can use them as a starting point for integrating the extension into their own projects.
- Interface detection through ERC-165
- ERC-165 defines a standard way to detect whether a contract reports support for a particular interface.
- Applications can use this capability to discover support for NFT relationship enhancement functionality.
- It helps avoid unsupported calls and is particularly useful in complex systems involving several interacting contracts.
- Improved interaction between contracts and applications
- Developers can check whether a contract supports the required interface and select alternative behavior when it does not.
- This can make applications more robust and improve the user experience.
For more on ERC-165, see the following article.
[ERC-165] Checking Whether a Contract Supports a Particular Interface
INFTGraph interface
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC165/IERC165.sol"; // Import IERC165 for interface detection
interface INFTGraph is IERC165 {
// setRelationship: Establishes relationships between NFTs.
function setRelationship(uint256 _originalID, uint256 _derivativeID, uint256 _attribute) external;
// setAttribute: Sets quantifiable attributes for NFTs.
function setAttribute(uint256 _id, string calldata _name, uint256 _value) external;
// getRelationship: Retrieves relationship values between NFTs.
function getRelationship(uint256 _originalID, uint256 _derivativeID) external view returns (uint256);
// getAttribute: Retrieves the value of specific attributes associated with NFTs.
function getAttribute(uint256 _id, string calldata _name) external view returns (bytes32);
// getAttributeNames: Retrieves all attribute names associated with an NFT.
function getAttributeNames(uint256 _id) external view returns (bytes32[] memory);
}The INFTGraph interface defines functions for setting relationships and attributes, as well as functions for retrieving attribute information and relationship values.
NFTGraph contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/introspection/ERC165.sol"; // Import ERC165 for interface detection
import "./INFTGraph.sol"; // Import INFTGraph interface
contract NFTGraph is INFTGraph{
mapping(uint256 => mapping(uint256 => uint256)) public relationship;
mapping(uint256 => mapping(bytes32 => bytes32)) public attributes;
// Implement the setRelationship and setAttribute functions as described in the EIP specification.
// Implement the supportsInterface function for ERC-165.
function supportsInterface(bytes4 interfaceID) public view override returns (bool) {
return interfaceID == type(INFTGraph).interfaceId || super.supportsInterface(interfaceID);
}
// Additional implementation details...
function getRelationship(uint256 _originalID, uint256 _derivativeID) external view returns (uint256) {
return relationship[_originalID][_derivativeID];
}
function getAttribute(uint256 _id, string calldata _name) external view returns (bytes32) {
return bytes32(attributes[_id][_name]);
}
function getAttributeNames(uint256 _id) external view returns (bytes32[] memory) {
bytes32[] memory names = new bytes32[](attributes[_id].length);
for (uint256 i = 0; i < attributes[_id].length; i++) {
names[i] = bytes32(attributes[_id][i]);
}
return names;
}
function setRelationship(uint256 originalNFT, uint256 derivativeNFT, uint256 relationshipValue) public {
require(originalNFT != derivativeNFT, "Original and derivative NFTs must be different");
relationship[originalNFT][derivativeNFT] = relationshipValue;
}
function setAttribute(uint256 nft, bytes32 attributeName, bytes32 attributeValue) public {
attributes[nft][attributeName] = attributeValue;
}
}The NFTGraph contract implements functions specified by INFTGraph and provides storage for relationships and attributes. This allows relationships to be established between NFTs and attributes to be assigned to individual NFTs.
The resulting data can represent networks of interactions and relationships within an NFT ecosystem.
Using the reference interface and contract
Developers can use the reference interface and contract to integrate NFT relationship enhancement into their projects.
The INFTGraph interface provides a common way to interact with the contract, promoting consistency and simplifying integration.
Feature overview
- Setting relationships
- Developers use
setRelationshipto establish a particular relationship between two NFTs. - This can model interactions such as one NFT influencing another.
- Developers use
- Assigning attributes
- Developers use
setAttributeto assign properties such as color, size, and rarity to individual NFTs, using the appropriate value encoding.
- Developers use
- Reading attributes and relationships
- Functions such as
getAttributeandgetRelationshipretrieve registered attribute and relationship information.
- Functions such as
Benefits
- Flexibility
- Adding relationships and attributes to NFTs supports more dynamic and interactive ecosystems.
- Consistency and standardization
- A common interface for contract interactions can simplify compatibility and integration across projects and applications.
- Development efficiency
- Using the reference interface and contract as a starting point can accelerate development and simplify integration of the relationship functionality.
These reference components provide a foundation for extending NFT applications and creating richer interactions for users.
Security
Developers implementing the proposal should consider the following security issues to protect contract integrity and the broader NFT ecosystem.
Validating relationships
- Problem
- Contracts using
setRelationshipmust ensure that established relationships are valid and authorized by the relevant parties. - Unauthorized or malicious relationships could produce unintended results.
- Contracts using
- Mitigation
- Implement a process to verify authorization before establishing a relationship.
- Additional logic can validate whether a relationship is legitimate and permitted under the application's rules.
Validating attributes
- Problem
- Contracts implementing
setAttributemust validate attribute values to prevent malicious or harmful inputs. - Invalid or unverified attributes could disrupt the NFT ecosystem.
- Contracts implementing
- Mitigation
- Validate attribute values against the permitted encoding, format, and range before storing them.
Access control
- Problem
- Access control is needed to restrict which users can invoke sensitive functions that modify relationships or attributes.
- Unauthorized access may enable abuse or unintended modifications.
- Mitigation
- Apply role-based access control or an allowlist of addresses authorized to invoke the relevant functions.
Reentrancy protection
- Problem
- Consider reentrancy protection for relationship and attribute modification functions, particularly if their implementations make external calls.
- Reentrancy vulnerabilities may allow attackers to manipulate contract behavior.
- Mitigation
- Where appropriate, use a reentrancy guard to prevent protected functions from being entered again before the ongoing invocation completes. The appropriate protection also depends on the contract's other callable functions and state invariants.
For more on reentrancy attacks, see the following article.
https://chaldene.net/solidity-reentrancy-attack
Addressing these considerations helps developers secure their implementations and protect the integrity of NFT relationships and attributes. This is important for user trust and broader adoption.
Citation
Guang (@xg1990), "ERC-7085: NFT Relationship Enhancement [DRAFT]," Ethereum Improvement Proposals, no. 7085, May 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7085.
Conclusion
ERC-7085 proposes a mechanism for managing relationships and attributes associated with ERC-721 and ERC-1155 NFTs.

