Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-5496 extends ERC-721 to manage multiple benefits attached to NFTs within smart contracts. It allows those benefits to be handled separately from NFT ownership, including when an NFT is sold or transferred.

This article explains the proposal, with additional context and examples.

ERC-5496 was in Last Call as of September 3, 2023, the date of the original article's research.

Overview

The proposal defines an extension to ERC-721 that introduces privileges associated with NFTs.

For background on ERC-721, see the following article.

https://chaldene.net/erc721

A privilege is a special right or benefit associated with an NFT. It can be exercised on-chain or off-chain. Examples include voting rights, eligibility to claim an airdrop, discounts at online stores, benefits at local restaurants, and access to airport VIP lounges.

A single NFT can carry multiple privileges. A privilege holder can assign a privilege to someone else, and its ownership can be checked on-chain.

Privileges may be shareable or non-shareable. Shareable privileges can be cloned so that additional users can benefit from them under the applicable rules. Each privilege can also have an expiration time.

Motivation

The proposal establishes a standard for managing NFT-associated privileges efficiently as ownership and assignments change.

NFTs can serve purposes beyond profile pictures or art collections. A fashion retailer could offer discounts to customers holding its NFTs. Members of a DAO could use membership NFTs to vote on treasury proposals. A dApp could offer airdrops to selected groups, such as holders of particular established NFT collections. A grocery store could issue NFT membership cards that provide benefits when customers shop.

However, an NFT owner may not want to use every associated benefit. The proposal provides a way to record and manage different privileges independently. This makes it possible to transfer or sell privileges without transferring ownership of the NFT itself.

ERC-721 records NFT ownership and transfers, but does not standardize separate privilege records. ERC-5496 associates privileges with specific NFTs and enables their holders to manage them individually, expanding the ways NFTs can provide practical utility.

Consider an airline that offers privileges to CryptoPunk holders to encourage them to join a club. If those privileges are issued separately without a mechanism linking them to the original NFT, selling the NFT may leave the benefits with the previous owner. The new owner does not necessarily receive them automatically. The proposal provides a way to associate privileges with the NFT while also allowing independent privilege management.

Specification

Contracts conforming to this standard must implement the IERC5496 interface. The cloneable multi-privilege extension is optional for ERC-721 contracts.

javascript
/// @title multi-privilege extension for EIP-721
///  Note: the EIP-165 identifier for this interface is 0x076e1bbb
interface IERC5496{
    /// @notice Emitted when `owner` changes the `privilege holder` of a NFT.
    event PrivilegeAssigned(uint256 tokenId, uint256 privilegeId, address user, uint256 expires);
    /// @notice Emitted when `contract owner` changes the `total privilege` of the collection
    event PrivilegeTotalChanged(uint256 newTotal, uint256 oldTotal);

    /// @notice set the privilege holder of a NFT.
    /// @dev expires should be less than 30 days
    /// Throws if `msg.sender` is not approved or owner of the tokenId.
    /// @param tokenId The NFT to set privilege for
    /// @param privilegeId The privilege to set
    /// @param user The privilege holder to set
    /// @param expires For how long the privilege holder can have
    function setPrivilege(uint256 tokenId, uint256 privilegeId, address user, uint256 expires) external;

    /// @notice Return the expiry timestamp of a privilege
    /// @param tokenId The identifier of the queried NFT
    /// @param privilegeId The identifier of the queried privilege
    /// @return Whether a user has a certain privilege
    function privilegeExpires(uint256 tokenId, uint256 privilegeId) external view returns(uint256);

    /// @notice Check if a user has a certain privilege
    /// @param tokenId The identifier of the queried NFT
    /// @param privilegeId The identifier of the queried privilege
    /// @param user The address of the queried user
    /// @return Whether a user has a certain privilege
    function hasPrivilege(uint256 tokenId, uint256 privilegeId, address user) external view returns(bool);
}

A conforming contract must establish the maximum privilege count before privileges are assigned. Privilege identifiers must be within the permitted range.

Calling setPrivilege emits the PrivilegeAssigned event, recording the assignment in the event log.

When the collection's total privilege count changes, the contract emits PrivilegeTotalChanged, allowing applications to monitor the change.

The ERC-165 supportsInterface function must return true when called with 0x076e1bbb, the interface identifier shown above.

javascript
/// @title Cloneable extension - Optional for EIP-721
interface IERC721Cloneable {
    /// @notice Emitted when set the `privilege ` of a NFT cloneable.
    event PrivilegeCloned(uint tokenId, uint privId, address from, address to);

    /// @notice set a certain privilege cloneable
    /// @param tokenId The identifier of the queried NFT
    /// @param privilegeId The identifier of the queried privilege
    /// @param referrer The address of the referrer
    /// @return Whether the operation is successful or not
    function clonePrivilege(uint tokenId, uint privId, address referrer) external returns (bool);
}

Calling clonePrivilege emits PrivilegeCloned, recording the cloning of a privilege.

The proposal also recommends using EIP-1271 for signature validation where applicable. EIP-1271 provides a mechanism for validating signatures on behalf of smart contract accounts.

Additional considerations

Shareable privileges

If a particular privilege cannot be shared, there is at most one holder of that privilege for each NFT. If it is shareable, the existing privilege holder can clone it for another person without surrendering their own privilege. This mechanism can encourage the distribution of benefits and wider adoption of NFTs.

Expiration time representation

Privilege expiration is represented by a timestamp stored as a uint256. Applications can use this value to determine whether a privilege is still valid.

Referrers and referral benefits

Suppose a local pizza restaurant offers a 30% discount coupon and encourages customers to share it with friends. Tom receives the coupon and shares it with Alice. Alice receives the benefit, and Tom becomes the referrer. In some cases, the restaurant may also reward Tom for the referral. This gives merchants a way to encourage customers to distribute promotions.

NFT transfers

The proposal addresses what happens when NFT ownership is transferred. Existing privilege assignments are not affected by the transfer. However, if a wrapped NFT is used, calling unwrap() to recover the underlying ERC-721 token may revert while privileges remain active.

Checking privilege expiration before unwrapping protects the rights of existing privilege holders.

The following example illustrates this behavior.

solidity
// unwrap() 関数の定義
function unwrap(uint256 tokenId, address to) external {
    // 特権の最後の有効期限を過ぎていることを確認
    require(getBlockTimestamp() >= privilegeBook[tokenId].lastExpiresAt, "特権はまだ有効です");

    // トークンの所有者が呼び出し者であることを確認
    require(ownerOf(tokenId) == msg.sender, "所有者でないため操作できません");

    // トークンを燃やして(削除して)特権の取得を無効化
    _burn(tokenId);

    // NFTトークンを指定されたアドレスに移動
    IERC721(nft).transferFrom(address(this), to, tokenId);

    // Unwrapイベントを発行
    emit Unwrap(nft, tokenId, msg.sender, to);
}

The original example's Japanese comments and revert messages are retained in the code. It checks that the recorded latest expiration has passed and that the caller owns the wrapped token, burns it, transfers the underlying NFT to the specified recipient, and emits Unwrap.

Backward compatibility

The proposal is compatible with NFTs that follow ERC-721. It introduces additional functionality and data structures without modifying the underlying ERC-721 interface.

Tests

Test examples are available here.

Source: https://eips.ethereum.org/EIPS/eip-5496

Reference implementation

javascript
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0; 

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "./IERC5496.sol";

contract ERC5496 is ERC721, IERC5496 {
    struct PrivilegeRecord {
        address user;
        uint256 expiresAt;
    }
    struct PrivilegeStorage {
        uint lastExpiresAt;
        // privId => PrivilegeRecord
        mapping(uint => PrivilegeRecord) privilegeEntry;
    }

    uint public privilegeTotal;
    // tokenId => PrivilegeStorage
    mapping(uint => PrivilegeStorage) public privilegeBook;
    mapping(address => mapping(address => bool)) private privilegeDelegator;

    constructor(string memory name_, string memory symbol_)
    ERC721(name_,symbol_)
    {
    
    }

    function setPrivilege(
        uint tokenId,
        uint privId,
        address user,
        uint64 expires
    ) external virtual {
        require((hasPrivilege(tokenId, privId, ownerOf(tokenId)) && _isApprovedOrOwner(msg.sender, tokenId)) || _isDelegatorOrHolder(msg.sender, tokenId, privId), "ERC721: transfer caller is not owner nor approved");
        require(expires < block.timestamp + 30 days, "expire time invalid");
        require(privId < privilegeTotal, "invalid privilege id");
        privilegeBook[tokenId].privilegeEntry[privId].user = user;
        if (_isApprovedOrOwner(msg.sender, tokenId)) {
            privilegeBook[tokenId].privilegeEntry[privId].expiresAt = expires;
            if (privilegeBook[tokenId].lastExpiresAt < expires) {
                privilegeBook[tokenId].lastExpiresAt = expires;
            }
        }
        emit PrivilegeAssigned(tokenId, privId, user, uint64(privilegeBook[tokenId].privilegeEntry[privId].expiresAt));
    }

    function hasPrivilege(
        uint256 tokenId,
        uint256 privId,
        address user
    ) public virtual view returns(bool) {
        if (privilegeBook[tokenId].privilegeEntry[privId].expiresAt >= block.timestamp){
            return privilegeBook[tokenId].privilegeEntry[privId].user == user;
        }
        return ownerOf(tokenId) == user;
    }

    function privilegeExpires(
        uint256 tokenId,
        uint256 privId
    ) public virtual view returns(uint256){
        return privilegeBook[tokenId].privilegeEntry[privId].expiresAt;
    }

    function _setPrivilegeTotal(
        uint total
    ) internal {
        emit PrivilegeTotalChanged(total, privilegeTotal);
        privilegeTotal = total;
    }

    function getPrivilegeInfo(uint tokenId, uint privId) external view returns(address user, uint256 expiresAt) {
        return (privilegeBook[tokenId].privilegeEntry[privId].user, privilegeBook[tokenId].privilegeEntry[privId].expiresAt);
    }

    function setDelegator(address delegator, bool enabled) external {
        privilegeDelegator[msg.sender][delegator] = enabled;
    }

    function _isDelegatorOrHolder(address delegator, uint256 tokenId, uint privId) internal virtual view returns (bool) {
        address holder = privilegeBook[tokenId].privilegeEntry[privId].user;
         return (delegator == holder || isApprovedForAll(holder, delegator) || privilegeDelegator[holder][delegator]);
    }

    function supportsInterface(bytes4 interfaceId) public override virtual view returns (bool) {
        return interfaceId == type(IERC5496).interfaceId || super.supportsInterface(interfaceId);
    }
}

The historical example is reproduced as published. Note that its setPrivilege parameter uses uint64 for expires, whereas the interface shown above uses uint256. These produce different function selectors, so the example should not be treated as a verified conforming implementation without resolving the mismatch and testing the relevant dependency version.

privilegeTotal

solidity
uint public privilegeTotal;

Overview

Stores the total number of privileges supported by the collection.

Details

This value represents the collection's privilege count and is updated when the configured count changes.


privilegeBook

solidity
mapping(uint => PrivilegeStorage) public privilegeBook;

Overview

Maps token IDs to their associated privilege information.

Details

Each token ID maps to a PrivilegeStorage struct containing the token's privilege records.

Key

  • uint
    • Token ID.

privilegeDelegator

solidity
mapping(address => mapping(address => bool)) private privilegeDelegator;

Overview

A nested mapping that manages privilege delegation between addresses.

Details

The stored Boolean indicates whether one address has authorized another to manage privileges on its behalf.

Keys

  • address
    • The address granting delegation.
  • address
    • The authorized delegate's address.

PrivilegeStorage

solidity
struct PrivilegeStorage {
    uint lastExpiresAt;
    mapping(uint => PrivilegeRecord) privilegeEntry;
}

Overview

A struct for storing and managing privileges.

Fields

  • lastExpiresAt
    • The latest recorded privilege expiration timestamp.
  • privilegeEntry
    • A mapping from privilege IDs to PrivilegeRecord structs.

PrivilegeRecord

solidity
struct PrivilegeRecord {
    address user;
    uint256 expiresAt;
}

Overview

A struct storing the details of an individual privilege assignment.

Fields

  • user
    • The address of the assigned privilege holder.
  • expiresAt
    • The timestamp at which the assignment expires.

constructor

javascript
constructor(string memory name_, string memory symbol_)
    ERC721(name_, symbol_)
{
    
}

Overview

The constructor initializes the ERC-721 token by passing its name and symbol to the parent constructor.

Details

The constructor executes during contract deployment and forwards the supplied token name and symbol to ERC-721 for initialization.

Parameters

  • name_
    • The token name.
  • symbol_
    • The token symbol.

setPrivilege

javascript
function setPrivilege(
        uint tokenId,
        uint privId,
        address user,
        uint64 expires
    ) external virtual {
        require((hasPrivilege(tokenId, privId, ownerOf(tokenId)) && _isApprovedOrOwner(msg.sender, tokenId)) || _isDelegatorOrHolder(msg.sender, tokenId, privId), "ERC721: transfer caller is not owner nor approved");
        require(expires < block.timestamp + 30 days, "expire time invalid");
        require(privId < privilegeTotal, "invalid privilege id");
        privilegeBook[tokenId].privilegeEntry[privId].user = user;
        if (_isApprovedOrOwner(msg.sender, tokenId)) {
            privilegeBook[tokenId].privilegeEntry[privId].expiresAt = expires;
            if (privilegeBook[tokenId].lastExpiresAt < expires) {
                privilegeBook[tokenId].lastExpiresAt = expires;
            }
        }
        emit PrivilegeAssigned(tokenId, privId, user, uint64(privilegeBook[tokenId].privilegeEntry[privId].expiresAt));
}

Overview

Assigns a privilege associated with a token.

Details

The function checks whether the caller is authorized: the token owner or an approved operator when the owner holds the privilege, or an address recognized by the privilege-holder/delegate check. It also checks that the proposed expiration is less than 30 days after the current block timestamp and that the privilege ID is within range.

If these checks pass, the function updates the assigned user. Only an owner or approved operator updates the stored expiration in this example. When necessary, the latest expiration is updated as well. Finally, the function emits the assignment event.

Parameters

  • tokenId
    • The ID of the relevant token.
  • privId
    • The privilege ID.
  • user
    • The recipient of the privilege.
  • expires
    • The proposed expiration timestamp, strictly less than 30 days after the current timestamp.

Return value

None.


hasPrivilege

javascript
function hasPrivilege(
        uint256 tokenId,
        uint256 privId,
        address user
    ) public virtual view returns(bool) {
        if (privilegeBook[tokenId].privilegeEntry[privId].expiresAt >= block.timestamp){
            return privilegeBook[tokenId].privilegeEntry[privId].user == user;
        }
        return ownerOf(tokenId) == user;
}

Overview

Determines whether a user holds a particular privilege associated with a token.

Details

If the stored expiration is greater than or equal to the current block timestamp, the function checks whether the queried address matches the assigned user. Otherwise, the privilege belongs to the current NFT owner.

Parameters

  • tokenId
    • The token ID.
  • privId
    • The privilege ID.
  • user
    • The address whose privilege is being checked.

Return value

  • bool
    • true if the address holds the privilege; otherwise false.

privilegeExpires

javascript
function privilegeExpires(
        uint256 tokenId,
        uint256 privId
    ) public virtual view returns(uint256){
        return privilegeBook[tokenId].privilegeEntry[privId].expiresAt;
}

Overview

Returns the expiration timestamp of a specific token's privilege assignment.

Parameters

  • tokenId
    • The token ID.
  • privId
    • The privilege ID.

Return value

  • uint256
    • The stored expiration timestamp.

_setPrivilegeTotal

javascript
function _setPrivilegeTotal(
        uint total
    ) internal {
        emit PrivilegeTotalChanged(total, privilegeTotal);
        privilegeTotal = total;
}

Overview

Sets the collection's total privilege count and emits an event containing the new and previous counts.

Parameters

  • total
    • The new total privilege count.

Return value

None.


getPrivilegeInfo

javascript
function getPrivilegeInfo(uint tokenId, uint privId) external view returns(address user, uint256 expiresAt) {
        return (privilegeBook[tokenId].privilegeEntry[privId].user, privilegeBook[tokenId].privilegeEntry[privId].expiresAt);
}

Overview

Retrieves the stored assignment information for a specific token and privilege.

Parameters

  • tokenId
    • The token ID.
  • privId
    • The privilege ID.

Return values

  • user
    • The stored privilege holder's address.
  • expiresAt
    • The stored expiration timestamp.

setDelegator

javascript
function setDelegator(address delegator, bool enabled) external {
        privilegeDelegator[msg.sender][delegator] = enabled;
}

Overview

Allows a user to authorize or revoke a delegate.

Details

This function records whether another address may manage privileges on behalf of the caller.

Parameters

  • delegator
    • The address to authorize as a delegate.
  • enabled
    • Whether the delegation is enabled.

Return value

None.


_isDelegatorOrHolder

javascript
function _isDelegatorOrHolder(address delegator, uint256 tokenId, uint privId) internal virtual view returns (bool) {
        address holder = privilegeBook[tokenId].privilegeEntry[privId].user;
         return (delegator == holder || isApprovedForAll(holder, delegator) || privilegeDelegator[holder][delegator]);
}

Overview

Checks whether an address is the stored privilege holder or an authorized operator or delegate of that holder.

Parameters

  • delegator
    • The address whose authorization is being checked.
  • tokenId
    • The token ID.
  • privId
    • The privilege ID.

Return value

  • bool
    • true if the address satisfies one of the authorization checks; otherwise false.

supportsInterface

javascript
function supportsInterface(bytes4 interfaceId) public override virtual view returns (bool) {
        return interfaceId == type(IERC5496).interfaceId || super.supportsInterface(interfaceId);
}

Overview

Checks whether the contract supports a specified interface.

Details

Returns true for the interface ID of IERC5496 and delegates other interface checks to the parent implementation.

Parameters

  • interfaceId
    • The interface identifier being checked.

Return value

  • bool
    • true if the interface is supported; otherwise false.

Security considerations

Implementations must carefully determine who is authorized to assign or clone privileges. Authorization checks should account for expiration, delegation, and changes in NFT ownership.

Citation

Jeremy Z (@wnft), "ERC-5496: Multi-privilege Management NFT Extension [DRAFT]," Ethereum Improvement Proposals, no. 5496, July 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5496.

Conclusion

ERC-5496 extends ERC-721 to manage multiple benefits attached to NFTs independently of the underlying token's ownership. Privilege assignments, expiration times, and optional cloning allow applications to handle benefits more flexibly when NFTs are sold or transferred.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777