ERC-5006 · Final · ERC · 2022-04-12
ERC-5006: Rental NFT, NFT User Extension
Adds a time-limited "user" role to ERC-1155 tokens, so an owner can rent out a quantity of a token for use without giving up ownership.
What problem does it solve?
Game items, passes and memberships are often ERC-1155 tokens, and their value comes from using them. Renting such an item has usually meant transferring it to the renter and trusting them to give it back, or building a custom escrow per game.
ERC-5006 separates owner from user for ERC-1155, as ERC-4907 does for ERC-721. A game or app checks the usable balance of an address to grant in-app rights, while ownership stays with the lender. Because the interface is standard, rental, lending or pay-to-own platforms can integrate with any compliant token without permission from its issuer.
How it works
Each rental is a user record:
struct UserRecord {
uint256 tokenId;
address owner;
uint64 amount;
address user;
uint64 expiry; // unix timestamp
}
| Function | Purpose |
|---|---|
createUserRecord(owner, user, tokenId, amount, expiry) |
Grant user the use of amount tokens until expiry; returns a recordId |
deleteUserRecord(recordId) |
End a record early or clean up an expired one |
usableBalanceOf(account, tokenId) |
How many tokens account may currently use |
frozenBalanceOf(account, tokenId) |
How many of the owner's tokens are locked in records |
userRecordOf(recordId) |
Read a record |
Rules from the spec: the caller must be the owner or approved via setApprovalForAll; user must not be the zero address; amount > 0; expiry must be in the future. Events CreateUserRecord and DeleteUserRecord let indexers follow rentals. supportsInterface returns true for 0xc26d96cc (ERC-165).
In the reference implementation, creating a record moves the tokens into the contract itself (so the owner cannot sell them mid-rental) and counts them as frozen. Deleting the record returns them to the owner. A user's usable balance only counts records whose expiry has not passed.
Sample code
Renting 5 copies of item #42 for 7 days and checking access (ethers v6):
import { Contract } from "ethers";
const abi = [
"function createUserRecord(address owner, address user, uint256 tokenId, uint64 amount, uint64 expiry) returns (uint256)",
"function usableBalanceOf(address account, uint256 tokenId) view returns (uint256)",
"event CreateUserRecord(uint256 recordId, uint256 tokenId, uint64 amount, address owner, address user, uint64 expiry)",
];
const items = new Contract(itemsAddress, abi, ownerSigner);
const expiry = BigInt(Math.floor(Date.now() / 1000) + 7 * 24 * 3600);
const tx = await items.createUserRecord(await ownerSigner.getAddress(), renter, 42n, 5n, expiry);
await tx.wait();
// In the game backend: gate features on usable balance, not ownership
const usable = await items.usableBalanceOf(renter, 42n);
if (usable > 0n) { /* unlock item */ }
Things to know
- Status is Final.
- Expiry is checked on read; an expired record keeps the tokens frozen until someone calls
deleteUserRecord. - Apps must actually read
usableBalanceOf; a plain ERC-1155balanceOfstill reports ownership, not usage rights. - The reference implementation caps the number of records per user and token to bound gas in
usableBalanceOf; check your implementation's limit. - For ERC-721 tokens use ERC-4907 instead.