ERC-5334 User-permission extension for NFT rentals (EIP-721 User And Expires And Level Extension)
Stagnant · NFTs & multi-token · created 2022-07-25
An ERC-721 extension standard that leaves NFT ownership untouched while granting a separate 'user' permission, limited to a set period and level, making lending or leasing easy.
Why it is needed
Without this standard, an owner wishing to lend out an NFT has no standardized way to let someone else use it without transferring ownership. Because there is no concept of 'user' separate from 'owner', each project has had to implement temporary usage rights on its own, using its own naming and approach such as 'operator' or 'controller', which are not interoperable with each other. Additionally, revoking usage rights once the rental period ends requires the owner to send a second on-chain transaction, which costs gas and may not be precisely timed, making it inefficient. As a result, even in cases that require separating ownership from usage rights, such as renting virtual land to build on or leasing game items, it is difficult for other projects to easily integrate that NFT's usage-rights functionality.
What to implement
event UpdateUser(uint256 indexed tokenId, address indexed user, uint64 expires, uint8 level);: An event recorded when an NFT's user, expires, or level changes.function setUser(uint256 tokenId, address user, uint64 expires, uint8 level) external;: Sets an NFT's user address, expiration time, and level.function userOf(uint256 tokenId) external view returns(address);: Queries an NFT's current user address. Returns the zero address if there is no user or the permission has expired.function userExpires(uint256 tokenId) external view returns(uint256);: Queries the timestamp (UNIX time) at which an NFT's user permission expires.function userLevel(uint256 tokenId) external view returns(uint256);: Queries the level of an NFT's user.
In depth
Separation of owner and user roles
This standard introduces a 'user' role separate from the ERC-721 owner role. The user only has rights to 'use' the NFT and cannot transfer ownership or designate another user. It is designed for situations where the owner and the user differ, such as building on virtual land or using a game asset within a game.
Setting up a rental with setUser
setUser(uint256 tokenId, address user, uint64 expires, uint8 level) sets the user address, expiration time (expires), and level (level) for tokenId all at once. Passing the zero address for user means no user is set. It reverts (throws) if tokenId is not a valid NFT. This function can be implemented as public or external.
Query functions userOf / userExpires / userLevel
userOf(tokenId) returns the current user address, or the zero address if there is no user or the user has expired. userExpires(tokenId) returns the UNIX timestamp at which the user's rights end, and userLevel(tokenId) returns the user's level. If there is no user, each returns a zero value. All three functions can be implemented as pure or view.
UpdateUser event
The UpdateUser(uint256 indexed tokenId, address indexed user, uint64 expires, uint8 level) event MUST be emitted whenever any of the user address, expires, or level changes. This lets wallets or marketplaces track on-chain changes.
Eliminating the second transaction via automatic expiration
Under the previous approach, once a rental period ended the owner had to send a second transaction to manually revoke the user's rights. This standard introduces the expires value so that, once the expiration time passes, query functions like userOf automatically reflect a 'no user' state, eliminating the extra transaction and gas cost.
Compatibility with ERC-721
This extension adds a new set of functions to ERC-721 and is fully compatible with existing ERC-721. It explains that because the new functions resemble existing ERC-721 functions in form, developers can adopt them quickly.
Standard status
This proposal is incomplete: the Rationale section is left as 'TBD' and the interface ID needed for supportsInterface is commented out. Its status is Stagnant and discussion is no longer progressing. This should be taken into account, as the specification could change or be discontinued before actual adoption.
Things to watch out for
- The owner can change the user at any time: The source text explains that because the owner can change an NFT's user, expires, and level at any time, this standard fully protects the owner's rights.