ERC-7589 · Draft · ERC · 2023-12-28
ERC-7589: Semi-Fungible Token Roles
A draft standard for lending out the use of ERC-1155 tokens: owners commit a balance, then grant time-limited, optionally revocable roles on it to other accounts without transferring ownership.
What problem does it solve?
ERC-1155 tracks who owns how many of each token, but says nothing about who may use them. Games and apps often want to rent out an in-game item, let a guild member use a pass, or delegate rights for a fixed period, without giving away the tokens themselves.
ERC-7589 adds a standard role layer for semi-fungible tokens, similar in spirit to ERC-7432 for NFTs. Each role assignment goes to one grantee and expires automatically.
How it works
Granting is a two-step process:
- Commit tokens.
commitTokens(grantor, tokenAddress, tokenId, amount)locks a specific amount (by depositing it in the roles contract or freezing it) and returns acommitmentId. - Grant a role.
grantRole(commitmentId, role, grantee, expirationDate, revocable, data)assigns abytes32role on that commitment.type(uint64).maxis recommended for a permanent role.
Other pieces:
revokeRoleends an assignment. The grantee can always give it up; the grantor can revoke only if it is revocable or expired.releaseTokens(commitmentId)returns the committed tokens, but must revert while any non-revocable, unexpired role remains.setRoleApprovalForAll(tokenAddress, operator, approved)lets an operator (e.g. a rental marketplace) commit and grant on the owner's behalf. These approvals are separate from ERC-1155 approvals.- Views:
grantorOf,tokenAmountOf,roleExpirationDate,isRoleRevocable,roleData, and others. - Role IDs are recommended to be
keccak256of the role name and arguments, e.g.keccak256("Player(uint256)"). - Optional extensions:
commitTokensAndGrantRole(one transaction) androleBalanceOf(total amount granted to a user for a role). There is also an optionalrolessection for ERC-1155 metadata JSON. - ERC-165 interface ID for the core interface:
0xc4c8a71d.
Sample code
Renting 5 units of an item for 7 days (ethers v6):
import { Contract, Wallet, JsonRpcProvider, id } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const owner = new Wallet(process.env.PRIVATE_KEY!, provider);
const roles = new Contract(rolesAddress, [
"event TokensCommitted(address indexed _grantor, uint256 indexed _commitmentId, address indexed _tokenAddress, uint256 _tokenId, uint256 _tokenAmount)",
"function commitTokens(address,address,uint256,uint256) returns (uint256)",
"function grantRole(uint256,bytes32,address,uint64,bool,bytes)",
], owner);
const receipt = await (await roles.commitTokens(owner.address, itemAddress, 42n, 5n)).wait();
const commitmentId = roles.interface.parseLog(receipt!.logs.find(l => l.address === rolesAddress)!)!.args._commitmentId;
const expires = BigInt(Math.floor(Date.now() / 1000) + 7 * 24 * 3600);
await roles.grantRole(commitmentId, id("Player()"), renterAddress, expires, false, "0x");
Things to know
- Status: Draft.
- Apps that honour roles must check
roleExpirationDatethemselves; expiry is not enforced by the token contract. - Commit may transfer or freeze balances, so access control on
commitTokensandreleaseTokensis security-critical. The spec also calls out reentrancy. - A non-revocable role locks the grantor's tokens until it expires.
- For single NFTs see ERC-7432; for a simpler "user" field on ERC-1155 rentals see ERC-5006.