ERC-5501 · Stagnant · ERC · 2022-08-18
ERC-5501: Rental & Delegation NFT - EIP-721 Extension
Proposed an ERC-721 `user` role with an expiry and an `isBorrowed` flag, so an NFT can be delegated to a hot wallet or rented out while it stays in the owner's wallet and the owner cannot cancel the rental early.
What problem does it solve?
Many NFTs are useful (game items, land, tickets, memberships), and the person using one is not always the owner. ERC-4907 added a time-limited user role, but the owner can reset the user at any moment. So rental marketplaces had to take custody of the NFT (staking it in a contract) to protect renters. While staked, the owner loses airdrops, free mints and other holder benefits, and cannot list the NFT for sale.
EIP-5501 adds one flag, isBorrowed, that locks the user role for the rental period, so the NFT can stay in the owner's wallet throughout.
How it works
The IERC5501 extension (ERC-165 ID 0xf808ec37) adds:
| Function | Purpose |
|---|---|
setUser(tokenId, user, expires, isBorrowed) |
Owner or approved operator sets the user, an expiry timestamp and the borrow flag |
userOf(tokenId) |
Current user; should revert if unset or expired |
userExpires(tokenId) |
When the user role ends |
userIsBorrowed(tokenId) |
Whether the role is a locked rental |
Two modes come out of this:
- Delegation (
isBorrowed = false): e.g. point the user role at a hot wallet. The owner can change it at any time, and it is cleared on transfer. - Rental (
isBorrowed = true):setUsermust revert untilexpireshas passed, and the user survives transfers, so the owner can even sell the NFT mid-rental.
A user must never be treated as an owner: no transfers, no approvals. Optional extensions add userBalanceOf, tokenOfUserByIndex, and a Terminable extension where lender and borrower each call setBorrowTermination and then anyone can call terminateBorrow to end a rental early.
Sample code
The core rule, sketched on top of OpenZeppelin ERC-721 (v5):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
abstract contract RentableSketch is ERC721 {
struct UserInfo { address user; uint64 expires; bool isBorrowed; }
mapping(uint256 => UserInfo) internal _users;
event UpdateUser(uint256 indexed tokenId, address indexed user, uint64 expires, bool isBorrowed);
function setUser(uint256 tokenId, address user, uint64 expires, bool isBorrowed) public {
require(user != address(0), "zero user");
_checkAuthorized(ownerOf(tokenId), msg.sender, tokenId);
UserInfo memory u = _users[tokenId];
require(!(u.isBorrowed && u.expires >= block.timestamp), "borrowed");
_users[tokenId] = UserInfo(user, expires, isBorrowed);
emit UpdateUser(tokenId, user, expires, isBorrowed);
}
function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address from) {
from = super._update(to, tokenId, auth);
if (from != to && !_users[tokenId].isBorrowed) { // delegation is cleared on transfer
delete _users[tokenId];
emit UpdateUser(tokenId, address(0), 0, false);
}
}
}
Things to know
- Status: Stagnant. ERC-4907 (Final) is the more widely known rental standard, and apps reading
userOfanduserExpirescan work with either. - A rental with a huge
expireslocks the owner out ofsetUserindefinitely unless the Terminable extension is implemented. - Since owner and user are both active at once, apps must decide which benefits go to which role to avoid "double spending" a perk.
- Marketplaces should show whether a listed NFT is currently borrowed.