EIPs Explained

ERC-7432 · Final · ERC · 2023-07-14

ERC-7432: Non-Fungible Token Roles

Lets NFT owners grant expiring, optionally irrevocable roles (bytes32 ids with custom data) to other accounts, so the utility of an NFT can be shared or rented without giving up ownership.

What problem does it solve?

An NFT often carries utility beyond ownership: access to a game, a property, an airdrop claim, a membership perk. Without a standard, sharing that utility means either transferring the NFT (losing it) or relying on each dApp's own delegation scheme.

ERC-7432 defines a generic role registry for NFTs. The owner grants a named role on a specific token to another account until a given time. dApps check the role instead of (or in addition to) ownership. Example from the spec: grant keccak256("PropertyManager()") to a manager and keccak256("PropertyTenant(uint256)") to a tenant of a digital property.

How it works

A role assignment is a Role struct:

Field Meaning
roleId bytes32, recommended keccak256("RoleName(input_types)")
tokenAddress, tokenId The NFT the role belongs to
recipient Who holds the role
expirationDate uint64 Unix time; the role lapses automatically
revocable If false, only the recipient can revoke it early
data Arbitrary bytes for role-specific parameters

Key behaviour:

  • grantRole reverts if the expiry is in the past or the caller is not the owner or an approved operator. Granting may lock the NFT, either by freezing it or moving it into escrow, and emits TokenLocked when it does.
  • revokeRole: the recipient can always revoke; the original owner can only revoke if revocable is true.
  • unlockToken returns or unfreezes the NFT, and must revert while any non-revocable role is still active.
  • setRoleApprovalForAll lets an operator (e.g. a rental marketplace) manage roles for an owner.
  • Views: ownerOf, recipientOf, roleData, roleExpirationDate, isRoleRevocable, isRoleApprovedForAll.

It is not an extension of ERC-721: it can live in a separate contract, so it works with existing, immutable NFT collections. The interface id is 0xd00ca5cf (ERC-165).

Sample code

Granting a tenant role for 30 days and checking it from a dApp contract:

bytes32 constant TENANT = keccak256("PropertyTenant(uint256)");

// owner side
roles.grantRole(IERC7432.Role({
    roleId: TENANT,
    tokenAddress: address(propertyNft),
    tokenId: 42,
    recipient: tenant,
    expirationDate: uint64(block.timestamp + 30 days),
    revocable: false,            // tenant is guaranteed the full term
    data: abi.encode(1_000e6)    // rent parameter
}));

// dApp side
function isTenant(address user) public view returns (bool) {
    return roles.recipientOf(address(propertyNft), 42, TENANT) == user
        && roles.roleExpirationDate(address(propertyNft), 42, TENANT) > block.timestamp;
}

Things to know

  • Status: Final.
  • Use type(uint64).max as the expiration for a role that should effectively never expire.
  • An optional metadata extension adds a roles array to ERC-721 JSON metadata, describing each role's name and the inputs encoded in data.
  • Related approaches: ERC-4907 adds a single time-limited "user" to an ERC-721; ERC-5982 is a role-based access control interface.
  • Always check expiry yourself as shown above; an expired assignment may still be stored until it is overwritten or revoked.

#nft #roles #rental #access-control #erc721

Details

Authors
Ernani São Thiago (@ernanirst), Daniel Lima (@karacurt)
Status
Final
Type
Standards Track / ERC
Created
2023-07-14
Requires

Machine-readable: Markdown · JSON