---
eip: 4400
label: ERC-4400
title: EIP-721 Consumable Extension
status: Final
type: Standards Track
category: ERC
created: 2021-10-30
requires: 165, 721
official: https://eips.ethereum.org/EIPS/eip-4400
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-4400.md
canonical: https://eips.huatuo.xyz/zh/eip-4400/
lang: zh
tldr: "为 ERC-721 NFT 增加一个标准的\"consumer\"角色：该地址可以使用代币的功能，但不能转移或授权代币，并且每次转移时自动重置。"
tags: [nft, erc721, roles, rental, utility]
---

# ERC-4400: EIP-721 Consumable Extension

> Interface extension for EIP-721 consumer role

**TL;DR:** 为 ERC-721 NFT 增加一个标准的"consumer"角色：该地址可以使用代币的功能，但不能转移或授权代币，并且每次转移时自动重置。

## 它解决什么问题？

NFT 往往有除所有权之外的用途：在元宇宙土地上部署场景、穿戴游戏内物品、进入活动现场。所有者常常希望让别人享受这些功能，而不必交出代币本身。许多项目为此各自发明了角色（`operator`、`contributor`、`user`……），名称和语义各不相同，因此市场和工具无法通用地支持它们。

ERC-4400 定义了一个最小化的标准角色，即 **consumer**，让租赁市场、质押合约和 dApp 都能以同样的方式读取和设置它。例如，质押合约可以持有你的 NFT，而你仍然是它的 consumer，可以继续在游戏中使用。

## 它如何运作

该扩展增加一个读取函数、一个修改函数和一个事件：

| 成员 | 作用 |
| --- | --- |
| `consumerOf(tokenId)` | 当前 consumer，没有则为 `address(0)` |
| `changeConsumer(consumer, tokenId)` | 设置或清除 consumer；所有者、被授权地址或 operator 均可调用 |
| `ConsumerChanged(owner, consumer, tokenId)` | 每次变更时触发 |

规则：

- consumer **不得**被视为所有者、operator 或被授权地址。它永远不能转移或授权代币。
- 每次转移时，consumer 都会重置为默认值，建议为 `address(0)`。因此 `Transfer` 事件也意味着 consumer 已被清除。
- consumer 实际上能*做*什么，由各个应用自行决定。
- `supportsInterface(0x953c8dfa)` 必须返回 `true`（[ERC-165](/eip-165/)）。

## 示例代码

基于 OpenZeppelin v5 `ERC721` 的最小实现：

```solidity
// 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);
    }
}
```

## 需要注意

- **状态：Final。**
- 没有内置的过期机制：consumer 会一直保留，直到被更改或代币被转移。如果需要带自动过期的限时租赁，可对比 [ERC-4907](/eip-4907/)（带 `expires` 时间戳的 `user`）以及面向 ERC-1155 的 [ERC-5006](/eip-5006/)。
- 安全责任在实现者身上：即使没有转移权限，如果赋予 consumer 本应只属于所有者的权力（例如销毁、修改元数据），也会让这个角色失去意义。
- 转移时清除意味着买家永远不会继承前任所有者设置的 consumer。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-4400
