ERC-4400 · Final · ERC · 2021-10-30
ERC-4400: EIP-721 Consumable Extension
Adds a standard "consumer" role to ERC-721 NFTs: an address that may use the token's utility without being able to transfer or approve it, reset automatically on every transfer.
What problem does it solve?
NFTs often have uses beyond ownership: deploying a scene on metaverse land, wearing an in-game item, entering an event. Owners frequently want to let someone else enjoy that utility without handing over the token. Many projects invented their own roles for this (operator, contributor, user…), each with different names and semantics, so marketplaces and tools could not support them generically.
ERC-4400 defines one minimal, standard role, the consumer, so that rental marketplaces, staking contracts and dApps can all read and set it the same way. For example, a staking contract can hold your NFT while you remain its consumer and keep using it in-game.
How it works
The extension adds one function to read, one to change and one event:
| Member | Purpose |
|---|---|
consumerOf(tokenId) |
Current consumer, or address(0) if none |
changeConsumer(consumer, tokenId) |
Set or clear the consumer; callable by owner, approved address or operator |
ConsumerChanged(owner, consumer, tokenId) |
Emitted on every change |
Rules:
- A consumer must not be treated as owner, operator or approved address. It can never transfer or approve the token.
- On every transfer the consumer is reset to a default, recommended to be
address(0). ATransferevent therefore also implies the consumer was cleared. - What a consumer may actually do is up to each application.
supportsInterface(0x953c8dfa)must returntrue(ERC-165).
Sample code
A minimal implementation on top of OpenZeppelin v5 ERC721:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
interface IERC721Consumable {
event ConsumerChanged(address indexed owner, address indexed consumer, uint256 indexed tokenId);
function consumerOf(uint256 tokenId) external view returns (address);
function changeConsumer(address consumer, uint256 tokenId) external;
}
contract ConsumableNFT is ERC721, IERC721Consumable {
mapping(uint256 => address) private _consumers;
constructor() ERC721("Land", "LAND") {}
function consumerOf(uint256 tokenId) external view returns (address) {
_requireOwned(tokenId);
return _consumers[tokenId];
}
function changeConsumer(address consumer, uint256 tokenId) external {
address owner = _requireOwned(tokenId);
require(_isAuthorized(owner, msg.sender, tokenId), "not authorised");
_consumers[tokenId] = consumer;
emit ConsumerChanged(owner, consumer, tokenId);
}
function _update(address to, uint256 tokenId, address auth) internal override returns (address from) {
from = super._update(to, tokenId, auth);
_consumers[tokenId] = address(0); // reset on every transfer
}
function supportsInterface(bytes4 id) public view override returns (bool) {
return id == 0x953c8dfa || super.supportsInterface(id);
}
}
Things to know
- Status: Final.
- There is no built-in expiry: the consumer stays until changed or the token is transferred. For time-limited rentals with automatic expiry, compare ERC-4907 (a
userwith anexpirestimestamp) and ERC-5006 for ERC-1155. - The security burden is on implementers: even without transfer rights, giving consumers powers that should belong only to owners (e.g. burning, changing metadata) defeats the purpose.
- Clearing on transfer means a buyer never inherits a previous owner's consumer.