EIPs Explained

ERC-1948 · Stagnant · ERC · 2019-04-18

ERC-1948: Non-fungible Data Token

Extends ERC-721 so each NFT carries a 32-byte data field that its owner can update over time, with an event recording every old and new value.

What problem does it solve?

ERC-721 metadata is typically fixed when a token is minted. Some use cases need state attached to the token itself that changes during its lifetime. The spec's examples: a collectible whose colour can change, an intellectual-property token recording current rights holders, or a token carrying data so it can be moved across chains.

ERC-1948 adds a small, standard slot for that changing data. The motivation came from side-chain and Plasma bridges and from a "distributed breeding" proposal, where NFTs need verifiable state that travels with them.

How it works

An ERC-721 contract adds:

  • readData(tokenId) → bytes32: returns the token's current data.
  • writeData(tokenId, newData): replaces the data. In the reference implementation only the current token owner may call it.
  • DataUpdated(tokenId, oldData, newData): emitted on every write, carrying both values so indexers can rebuild the history without reading storage.

The field is exactly 32 bytes. It can hold a value directly (a counter, an address, packed flags). For anything larger, the spec recommends storing the root hash of an authenticated structure such as a Merkle or Patricia tree and keeping the full data elsewhere.

Sample code

Implementation on top of OpenZeppelin's ERC-721 (v5):

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

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

contract DataNFT is ERC721 {
    event DataUpdated(uint256 indexed tokenId, bytes32 oldData, bytes32 newData);

    mapping(uint256 => bytes32) private _data;

    constructor() ERC721("DataNFT", "DNFT") {}

    function mint(address to, uint256 tokenId) external {
        _mint(to, tokenId); // add access control in real code
    }

    function readData(uint256 tokenId) external view returns (bytes32) {
        _requireOwned(tokenId); // reverts if the token does not exist
        return _data[tokenId];
    }

    function writeData(uint256 tokenId, bytes32 newData) external {
        require(msg.sender == ownerOf(tokenId), "not owner");
        emit DataUpdated(tokenId, _data[tokenId], newData);
        _data[tokenId] = newData;
    }
}

Watching updates (ethers v6):

nft.on("DataUpdated", (tokenId, oldData, newData) => {
  console.log(`token ${tokenId}: ${oldData} -> ${newData}`);
});

Things to know

  • Status is Stagnant. The interface is tiny and easy to copy, but it never became a widely adopted standard.
  • Only the owner can write, so a game or protocol that needs to update tokens on its own needs different access rules. That would be a departure from this spec.
  • Anyone buying the token gets whatever data the previous owner last wrote. Marketplaces should show readData so buyers know the current state.
  • If you only need to tell marketplaces that off-chain metadata changed, ERC-4906 (MetadataUpdate events) is the widely supported option.

#nft #dynamic-data #erc721 #metadata #erc

Details

Authors
Johann Barbie (@johannbarbie), Ben Bollen <[email protected]>, pinkiebell (@pinkiebell)
Status
Stagnant
Type
Standards Track / ERC
Created
2019-04-18
Requires

Machine-readable: Markdown · JSON