ERC-7508 · Draft · ERC · 2023-08-15
ERC-7508: Dynamic On-Chain Token Attributes Repository
A shared on-chain repository where any ERC-721 or ERC-1155 collection, including existing ones, can store typed per-token attributes that other contracts can read directly.
What problem does it solve?
Most NFT attributes ("strength: 12", "rarity: gold") live in off-chain JSON. Smart contracts cannot read them, so a game cannot trust a character's stats without an oracle, and if the hosting disappears the attributes disappear too.
ERC-7508 proposes a single, permissionless attributes repository contract that any ERC-721 or ERC-1155 collection can use. Because it is a separate common-good contract rather than an extension, even collections deployed long before it can start storing attributes on-chain. Use cases in the spec include cross-collection games, tokens that evolve as their owners act, and supply-chain items whose state moves from "pending" to "shipped" to "delivered".
How it works
- Typed key/value storage. Attributes are stored per
(collection, tokenId, key)in six types:address,bool,bytes,int256,stringanduint256. Each has a getter and setter (getUintAttribute,setStringAttribute, …), plus batch variants and a combinedgetAttributes/setAttributes. - Collection-wide values. Using
tokenId = type(uint256).maxstores attributes shared by the whole collection. - Access control per key. A collection is first registered with
registerAccessControl(owner either read fromOwnableor set manually). The owner then chooses, per key, who may write:Owner,Collaborator,OwnerOrCollaborator,TokenOwneror aSpecificAddress. - Presigned writes. An authorised setter can sign an attribute update off-chain (with a deadline and a chain-specific
DOMAIN_SEPARATOR) and anyone can submit it viapresignedSet…Attribute. - Schema. Collections can publish a metadata URI describing their attributes (name, type, display hints, min/max…), set with
setAttributesMetadataURIForCollection. - Gas. Strings for keys and values are stored once and referenced by index, so later users of the same string pay less.
Every write emits a typed …AttributeUpdated event. The ERC-165 interface ID is 0x212206a8.
Sample code
A game contract reading and updating a character's level in the repository:
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.21;
interface IERC7508Min {
function getUintAttribute(address collection, uint256 tokenId, string memory key)
external view returns (uint256);
function setUintAttribute(address collection, uint256 tokenId, string memory key, uint256 value)
external;
}
contract Arena {
IERC7508Min public immutable repo;
address public immutable heroes;
constructor(IERC7508Min _repo, address _heroes) { repo = _repo; heroes = _heroes; }
// Requires the collection owner to have granted this contract write access
// to the "level" key (e.g. as a Collaborator or SpecificAddress).
function win(uint256 heroId) external {
uint256 level = repo.getUintAttribute(heroes, heroId, "level");
repo.setUintAttribute(heroes, heroId, "level", level + 1);
}
}
Things to know
- Status is Draft. The interface may still change.
- The spec intends one deployment at the same address on every chain (starting
0xA77B75), but the final address is listed as TBD. Do not hard-code one from unofficial sources. - The repository does not check that a token exists, except where the
TokenOwneraccess type requires an owner lookup. - A presigned message can be replayed until its deadline. Keep deadlines short if your logic expects attributes to change back later.
- It comes from the same authors as nestable NFTs (ERC-7401) and can be combined with them.