---
eip: 5380
label: ERC-5380
title: ERC-721 Entitlement Extension
status: Final
type: Standards Track
category: ERC
created: 2022-03-11
requires: 165, 721, 1046
official: https://eips.ethereum.org/EIPS/eip-5380
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5380.md
canonical: https://eips.huatuo.xyz/zh/eip-5380/
lang: zh
tldr: 允许 ERC-721 所有者在不转移所有权的情况下，授予其他地址使用其代币特定属性的权利，例如在游戏中打出一张卡牌。
tags: [nft, erc-721, rental, delegation, permissions]
---

# ERC-5380: ERC-721 Entitlement Extension

> Allows token owners to grant the ability for others to use specific properties of those tokens

**TL;DR:** 允许 ERC-721 所有者在不转移所有权的情况下，授予其他地址使用其代币特定属性的权利，例如在游戏中打出一张卡牌。

## 它解决什么问题？

拥有 NFT 和使用 NFT 往往是两种不同的需求。有人可能想在链上游戏中使用一张交易卡牌而不购买它，或者想获得 NFT 所指向媒体的使用许可。把代币转给对方意味着交出完整所有权，远超所需。

有些权利是稀缺的（同一时间只应有一位玩家持有一张卡牌，否则所有者就能把它"租"给所有人），有些则不然（媒体的使用权可以授予很多人）。ERC-5380 把这两种情形都建模为**权益（entitlement）**：代币的具名属性，所有者可以分配，并且每个属性都有可持有用户数量的上限。

## 它如何运作

权益合约是一个独立的合约，代表一个"属性"。它的关键函数接收 NFT 合约地址和代币 ID：

| 函数 | 用途 |
| --- | --- |
| `entitle(user, contract, tokenId)` | 代币所有者把此权益分配给 `user` |
| `maxEntitlements(contract, tokenId)` | 同一时间最多可有多少用户持有 |
| `entitlementOf(user, contract, tokenId)` | `user` 拥有多少权益；默认情况下全部归当前所有者 |

发生变化时会触发 `EntitlementChanged(user, contract, tokenId)`。当调用者不是所有者时，`entitle` 不应 revert（只是什么都不做）。游戏或应用在允许某人使用代币之前，会检查 `entitlementOf`。

另有两个可选的推荐扩展：**可枚举**扩展（列出某用户拥有权益的代币），以及**元数据**扩展，其 `tokenURI()` 遵循 [ERC-1046](/eip-1046/)，其中 `interop` 块设置 `erc5380: true`。

ERC-20 和 ERC-1155 被有意排除在外，因为部分所有权比"拥有 / 不拥有"难追踪得多。

## 示例代码

规范中把一个参数命名为 `contract`，而它是 Solidity 的保留字，所以实际代码必须改名。下面是可编译的基础接口版本，以及游戏侧的检查：

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IERC5380Entitlement {
    event EntitlementChanged(address indexed user, address indexed tokenContract, uint256 indexed tokenId);
    function entitle(address user, address tokenContract, uint256 tokenId) external;
    function maxEntitlements(address tokenContract, uint256 tokenId) external view returns (uint256);
    function entitlementOf(address user, address tokenContract, uint256 tokenId) external view returns (uint256);
}

contract CardGame {
    IERC5380Entitlement public immutable playRight;
    address public immutable cards;

    constructor(IERC5380Entitlement _playRight, address _cards) {
        playRight = _playRight;
        cards = _cards;
    }

    function play(uint256 cardId) external {
        require(playRight.entitlementOf(msg.sender, cards, cardId) > 0, "not entitled");
        // ... game logic
    }
}
```

## 需要注意

- 状态：**Final**。
- 规范中的 Solidity 有一些小错误（保留字 `contract`，`maxEntitlements` 缺少 `returns`），因此实现时要重命名参数；这影响的是源代码，而不是 ABI 类型。
- 它是作为 [ERC-4907](/eip-4907/) 的替代设计被提出的，后者直接给 NFT 增加一个有时间限制的 `user` 角色。
- 只有当使用方应用去检查权益时，权益才有意义；持有权益不会改变 `ownerOf`。


---

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