---
eip: 5187
label: ERC-5187
title: Extend EIP-1155 with rentable usage rights
status: Stagnant
type: Standards Track
category: ERC
created: 2022-04-17
requires: 165, 1155
official: https://eips.ethereum.org/EIPS/eip-5187
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5187.md
canonical: https://eips.huatuo.xyz/zh/eip-5187/
lang: zh
tldr: 一种 ERC-1155 扩展，将所有权与有时限的使用权分离，使同一所有者可以同时把一个 NFT 租给多个用户，并支持转租、续租和到期后收回。
tags: [nft, rental, erc-1155, usage-rights]
---

# ERC-5187: Extend EIP-1155 with rentable usage rights

> Separate ownership and usage rights of EIP-1155 to allow users to use NFTs for an allotted time and return them to owners after expiration.

**TL;DR:** 一种 ERC-1155 扩展，将所有权与有时限的使用权分离，使同一所有者可以同时把一个 NFT 租给多个用户，并支持转租、续租和到期后收回。

## 它解决什么问题？

NFT 租赁通常依赖超额抵押、托管方或信任。游戏公会把道具借给新玩家，或艺术家在一段时间内把作品租给媒体，都需要一种方式：交出**使用权**而不交出**所有权**，并在期限结束时自动收回。

ERC-5187 扩展了 [ERC-1155](/eip-1155/)，让使用权成为独立、可转让、会过期的单元。所有者保留产权，甚至可以在租期内出售它而不影响租户。

## 它如何运作

`IRental` 接口（ERC-165 ID `0x6938e358`）增加了：

| 函数 | 用途 |
| --- | --- |
| `safeRent(from, to, id, amount, expire)` | 把代币 `id` 的 `amount` 份使用权租给 `to`，直到 `expire` |
| `takeBack(user, tokenId)` | 租期结束后，所有者收回使用权 |
| `renew(user, id, expire)` | 延长用户的租期 |
| `sublet(to, id)` | 用户把自己的使用权转给另一个用户 |
| `propertyRightOf(id)` | 产权的所有者 |
| `expireAt(id, user)` | 用户的租期何时结束 |
| `totalSupply(id)` | 某个代币 ID 的总供应量 |

`Rented`、`Renew`、`Sublet` 和 `TakeBack` 事件用于跟踪生命周期。

设计理由中的关键想法：

- 一个所有者可以按不同条款**同时**向**多个用户**出租使用权。
- 用户可以自由**转租**；转租回所有者就是提前归还的方式。
- 续租需向所有者申请，由所有者调用 `renew`。

## 示例代码

检查玩家当前是否可以使用某件道具：

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

interface IRental {
    function expireAt(uint256 id, address user) external view returns (uint256);
    function propertyRightOf(uint256 id) external view returns (address);
}

contract Game {
    IRental public immutable items;

    constructor(IRental _items) {
        items = _items;
    }

    function canUse(address player, uint256 itemId) public view returns (bool) {
        if (items.propertyRightOf(itemId) == player) return true;   // owner
        return items.expireAt(itemId, player) > block.timestamp;    // active tenant
    }
}
```

规范没有说明 `expire` 是时间戳还是时长；这个示例假定为 Unix 时间戳。

## 需要注意

- 状态为 **Stagnant**，规范的安全考虑部分只写了“Needs discussion”。
- 有几处细节规定得不够明确（`expire` 的单位、谁可以调用 `takeBack` 和 `renew`、使用权与 ERC-1155 余额的关系）。请阅读你所依赖的实现。
- 对于 ERC-721，已 Final 的 [ERC-4907](/eip-4907/) 增加了单个有时限的 `user` 角色，[ERC-5006](/eip-5006/) 则为 ERC-1155 增加了用户记录；两者被引用得更广泛。


---

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