ERC-1948 NFT with mutable data storage (Non-fungible Data Token)
Stagnant · NFTs & multi-token · created 2019-04-18
A standard that adds a 32-byte data field to an NFT, allowing the owner to read and write data even after the token has been minted.
Why it is needed
With standard ERC-721 metadata, once a token's metadata is set at mint time, it cannot be changed afterward. But there are cases where a token's state needs to keep changing, such as color-changing CryptoKitties, intellectual property tokens whose rights holder changes over time, or tokens that move between sidechains or plasma chains and need to carry their data along with them. Without a standard for storing this kind of dynamic data, each project ends up building its own ad hoc storage in a different way, making it hard for protocols like sidechain bridges or decentralized breeding to stay compatible across different implementations.
What to implement
event DataUpdated(uint256 indexed tokenId, bytes32 oldData, bytes32 newData);: An event emitted when the data for tokenId changes from oldData to newData. oldData or newData may be empty.function readData(uint256 tokenId) external view returns (bytes32);: Returns the current data stored for the given tokenId as a bytes32 value.function writeData(uint256 tokenId, bytes32 newData) external;: Writes newData to storage for the given tokenId and emits a DataUpdated event.
In depth
Data field structure
A single 32-byte (bytes32) data field is stored per tokenId in a mapping. Values are independent per token, and this field can be updated separately even after minting.
The readData function
readData(tokenId) is a view function that returns the bytes32 value currently stored. In the example implementation, it first checks that the tokenId actually exists (_exists).
Access control for writeData
writeData(tokenId, newData) can only update the data when the caller (msg.sender) matches the owner (ownerOf) of that tokenId. The call fails if the caller is not the owner.
The DataUpdated event
Every time writeData is executed, a DataUpdated(tokenId, oldData, newData) event is emitted. oldData is the value before the update and newData is the value after, and both can be empty bytes.
Handling data larger than 32 bytes
The data field is meant for storing simple values directly, such as counters or addresses. If more data is needed, the proposal suggests using an authenticated data structure such as a Merkle tree or Patricia tree and storing only its root hash in the bytes32 field.
Usage context
This proposal originated from a distributed breeding protocol, and explains that tokens with dynamic data would be helpful when interacting with sidechain bridges such as xDAI or Plasma chains.
ERC-721 extension structure
The IERC1948 interface is designed to extend ERC-721, so it can be applied to an existing NFT contract by simply adding readData, writeData, and DataUpdated.
Proposal status
This ERC is in Stagnant status, a proposal where discussion has stopped and is no longer progressing.