EIPs Explained

ERC-8048 · Draft · ERC · 2025-09-30

ERC-8048: Onchain Metadata for Token Registries

A small key-value interface, metadata(tokenId, key) returning bytes, that lets ERC-721, ERC-1155 and ERC-6909 contracts store token metadata fully onchain instead of in tokenURI JSON or data URLs.

What problem does it solve?

NFT and multi-token contracts usually point to offchain JSON through tokenURI / uri. Projects that want metadata fully onchain have mostly packed it into data: URLs returned by tokenURI, which costs a lot of gas, is awkward to parse onchain, and complicates storage proofs. There was no uniform way to store and read individual onchain metadata fields.

ERC-8048 adds a simple per-token key-value store that works alongside ERC-721, ERC-1155 and ERC-6909.

How it works

Core interface (ERC-165 ID 0xdf670be1):

function metadata(uint256 tokenId, string calldata key) external view returns (bytes memory);
event MetadataSet(uint256 indexed tokenId, string indexed indexedKey, string key, bytes value);
  • Keys are case-sensitive strings; values are arbitrary bytes. Keys may carry parameters, such as "name/Maria".
  • A setMetadata(tokenId, key, value) writer is optional; the write policy is up to the contract. Every write must emit MetadataSet.
  • Contracts may use Diamond Storage under the namespace "erc8048.onchain.metadata.storage".

Agent profile ("ERC-721T"). Reserved keys for NFTs that represent AI agents: context (UTF-8 Markdown, optionally with embedded JSON), endpoint[<type>] with lowercase types mcp, a2a, web, x402, and address[<chain-id>] / account[<chain-id>][<index>], where the chain ID uses the ERC-7930 chain identifier format. Marketplace JSON in tokenURI stays as is.

Optional extensions:

  • Metadata authority (ID 0xf9cb127d): metadataAuthority(tokenId) names an address, other than the owner, that alone may write metadata (for example a registry maintaining regulated fields of a tokenized asset). If none is set, the owner, the approved address or an operator may write. Only for tokens with a unique owner.
  • Metadata contract reference: already-deployed tokens can add "metadata_contract": "0x…" to their tokenURI JSON, pointing to a separate contract on the same chain that implements metadata(...).

Sample code

Minimal implementation (writes restricted to the token owner):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract OnchainMetaNFT is ERC721 {
    event MetadataSet(uint256 indexed tokenId, string indexed indexedKey, string key, bytes value);
    mapping(uint256 => mapping(string => bytes)) private _meta;

    constructor() ERC721("Agents", "AGT") {}

    function metadata(uint256 tokenId, string calldata key) external view returns (bytes memory) {
        return _meta[tokenId][key];
    }

    function setMetadata(uint256 tokenId, string calldata key, bytes calldata value) external {
        require(ownerOf(tokenId) == msg.sender, "not owner");
        _meta[tokenId][key] = value;
        emit MetadataSet(tokenId, key, key, value);
    }

    function supportsInterface(bytes4 id) public view override returns (bool) {
        return id == 0xdf670be1 || super.supportsInterface(id);
    }
}

Reading an agent's MCP endpoint (ethers v6):

const raw = await nft.metadata(1n, "endpoint[mcp]");
console.log(toUtf8String(raw)); // e.g. "https://agents.example.com/mcp/1"

Things to know

  • Status: Draft. The agent profile and extensions have been evolving; check the current spec before relying on key names or interface IDs.
  • Storing large values onchain is expensive; keep values small or store hashes and URIs.
  • The spec tells clients to treat context and endpoint values as untrusted input, and to call a metadata_contract only if they trust it.
  • Transferring the token transfers the onchain records, not any server, key or funds those records point to. For agent identity and reputation registries see ERC-8004.

#nft #metadata #onchain #token #agents

Details

Authors
Prem Makeig (@nxt3d), Rafael Abuawad (@rafael-abuawad)
Status
Draft
Type
Standards Track / ERC
Created
2025-09-30
Requires
Required by

Machine-readable: Markdown · JSON