ERC-7085 · Draft · ERC · 2023-05-02
ERC-7085: NFT Relationship Enhancement
A draft extension that lets NFT contracts record weighted 'original to derivative' links between tokens and named numeric attributes on each token, turning a collection into a queryable graph.
What problem does it solve?
ERC-721 and ERC-1155 treat every token as isolated. There is no on-chain way to say "token 7 is a derivative of token 3, with weight 50" or "token 9 has power = 12". Projects that need remixes, family trees, crafting recipes or game stats invent their own storage and functions, so tools can't read them generically.
ERC-7085 proposes a small common interface for these relationships and quantifiable attributes, so a set of NFTs can be treated as a graph.
How it works
Five functions are added to an NFT contract:
| Function | Purpose |
|---|---|
setRelationship(originalID, derivativeID, attribute) |
Link a derivative to its original with a numeric value (defaults to 1) |
getRelationship(originalID, derivativeID) |
Read that value (uint256) |
setAttribute(id, name, value) |
Set one named numeric attribute on a token |
getAttribute(id, name) |
Read an attribute (returned as bytes32) |
getAttributeNames(id) |
List a token's attribute names |
Design choices in the spec: only one relationship can exist between a given pair of tokens, which keeps the graph simple, and attributes are set one at a time to keep each call cheap. The interface (INFTGraph) is discoverable via ERC-165.
Who may set relationships or attributes is not defined. The spec only warns that implementers must add access control and validate that relationships are authorized by the relevant parties.
Sample code
A minimal, compiling take on the interface with owner-only writes:
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;
contract NFTGraph {
address public immutable admin = msg.sender;
mapping(uint256 => mapping(uint256 => uint256)) private _rel;
mapping(uint256 => mapping(bytes32 => bytes32)) private _attr;
mapping(uint256 => bytes32[]) private _names;
modifier onlyAdmin() { require(msg.sender == admin, "not admin"); _; }
function setRelationship(uint256 original, uint256 derivative, uint256 value) external onlyAdmin {
require(original != derivative, "same token");
_rel[original][derivative] = value == 0 ? 1 : value;
}
function getRelationship(uint256 original, uint256 derivative) external view returns (uint256) {
return _rel[original][derivative];
}
function setAttribute(uint256 id, string calldata name, uint256 value) external onlyAdmin {
bytes32 key = keccak256(bytes(name));
if (_attr[id][key] == 0) _names[id].push(key);
_attr[id][key] = bytes32(value);
}
function getAttribute(uint256 id, string calldata name) external view returns (bytes32) {
return _attr[id][keccak256(bytes(name))];
}
function getAttributeNames(uint256 id) external view returns (bytes32[] memory) {
return _names[id]; // hashed keys in this sketch
}
}
Things to know
- Status is Draft, and the text is internally inconsistent:
setAttributetakes auint256value whilegetAttributereturnsbytes32,getAttributeNamesreturnsbytes32[]for string names, and the reference contract would not compile as written. Expect implementations to differ. - No ERC-165 interface id is fixed in the spec beyond
type(INFTGraph).interfaceId, which depends on the exact final signatures. - Relationship values are just numbers; their meaning (royalty share, similarity, quantity) is up to each application.
- Without strict access control anyone could link unrelated tokens or overwrite attributes, which the spec lists as its main security concern.