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.

This article examines ERC7432, which proposes an interface for managing various roles associated with NFTs.

This article translates, summarizes, and expands on the following proposal.

As of September 7, 2023, ERC7432 was at the Review stage.

Overview

This standard proposes a mechanism for assigning specific roles to NFTs. Roles are associated with individual NFTs and automatically become invalid once a predefined expiration time passes. A role refers to specific functionality or privileges, such as those of an administrator or an owner. Roles are represented by bytes32 values and have an additional custom _data field. The _data field allows arbitrary information associated with a role to be stored and customized.

Motivation

This interface aims to provide a standard for managing NFT roles. By adopting it, decentralized applications (dApps) can implement access controls for privileged operations. For example, a dApp can restrict token issuance or eligibility for an airdrop to particular users.

NFT role management integrates with dApps and provides a mechanism for sharing utility, such as functionality and privileges. Consider digital real estate as an example. A user can create a digital property NFT and assign another user the PROPERTY_MANAGER role. This delegates specific functionality or privileges without transferring ownership. The same user can assign a PROPERTY_TENANT role to multiple users, allowing the addresses holding that role to access and interact with the digital property.

There are also applications in decentralized finance (DeFi). An insurance policy could be issued as an NFT, with its beneficiaries, insured parties, and insurers tracked on-chain. This makes it possible to manage the roles of policyholders and other participants transparently and reliably.

Specification

Contracts conforming to this standard must implement the following interface.

javascript
/// @title ERC-7432 Non-Fungible Token Roles
/// @dev See https://eips.ethereum.org/EIPS/eip-7432
/// Note: the ERC-165 identifier for this interface is 0xd7e151ef.
interface IERC7432 /* is ERC165 */ {
  
    /** Events **/

    /// @notice Emitted when a role is granted.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user assigning the role.
    /// @param _grantee The user receiving the role.
    /// @param _expirationDate The expiration date of the role.
    /// @param _data Any additional data about the role.
    event RoleGranted(
        bytes32 indexed _role,
        address indexed _tokenAddress,
        uint256 indexed _tokenId,
        address _grantor,
        address _grantee,
        uint64 _expirationDate,
        bytes _data
    );

    /// @notice Emitted when a role is revoked.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _revoker The user revoking the role.
    /// @param _grantee The user that receives the role revocation.
    event RoleRevoked(
        bytes32 indexed _role,
        address indexed _tokenAddress,
        uint256 indexed _tokenId,
        address _revoker,
        address _grantee
    );

    /// @notice Emitted when a user is approved to manage any role on behalf of another user.
    /// @param _tokenAddress The token address.
    /// @param _operator The user approved to grant and revoke roles.
    /// @param _isApproved The approval status.
    event RoleApprovalForAll(
        address indexed _tokenAddress,
        address indexed _operator,
        bool _isApproved
    );

    /// @notice Emitted when a user is approved to manage the roles of an NFT on behalf of another user.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _operator The user approved to grant and revoke roles.
    /// @param _isApproved The approval status.
    event RoleApproval(
        address indexed _tokenAddress,
        uint256 indexed _tokenId,
        address _operator,
        bool _isApproved
    );

    /** External Functions **/ 

    /// @notice Grants a role to a user.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantee The user receiving the role.
    /// @param _expirationDate The expiration date of the role.
    /// @param _data Any additional data about the role.
    function grantRole(
        bytes32 _role,
        address _tokenAddress,
        uint256 _tokenId,
        address _grantee,
        uint64 _expirationDate,
        bytes calldata _data
    ) external;

    /// @notice Revokes a role from a user.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantee The user that receives the role revocation.
    function revokeRole(
        bytes32 _role,
        address _tokenAddress,
        uint256 _tokenId,
        address _grantee
    ) external;

    /// @notice Grants a role on behalf of a user.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user assigning the role.
    /// @param _grantee The user that receives the role.
    /// @param _expirationDate The expiration date of the role.
    /// @param _data Any additional data about the role.
    function grantRoleFrom(
        bytes32 _role,
        address _tokenAddress,
        uint256 _tokenId,
        address _grantor,
        address _grantee,
        uint64 _expirationDate,
        bytes calldata _data
    ) external;

    /// @notice Revokes a role on behalf of a user.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _revoker The user revoking the role.
    /// @param _grantee The user that receives the role revocation.
    function revokeRoleFrom(
        bytes32 _role,
        address _tokenAddress,
        uint256 _tokenId,
        address _revoker,
        address _grantee
    ) external;

    /// @notice Approves operator to grant and revoke any roles on behalf of another user.
    /// @param _tokenAddress The token address.
    /// @param _operator The user approved to grant and revoke roles.
    /// @param _approved The approval status.
    function setRoleApprovalForAll(
        address _tokenAddress,
        address _operator,
        bool _approved
    ) external;

    /// @notice Approves operator to grant and revoke roles of an NFT on behalf of another user.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _operator The user approved to grant and revoke roles.
    /// @param _approved The approval status.
    function approveRole(
        address _tokenAddress,
        uint256 _tokenId,
        address _operator,
        bool _approved
    ) external;

    /** View Functions **/

    /// @notice Checks if a user has a role.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user that assigned the role.
    /// @param _grantee The user that received the role.
    function hasRole(
      bytes32 _role,
      address _tokenAddress,
      uint256 _tokenId,
      address _grantor,
      address _grantee
    ) external view returns (bool);
  
    /// @notice Checks if a user has a unique role.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user that assigned the role.
    /// @param _grantee The user that received the role.
    function hasUniqueRole(
      bytes32 _role,
      address _tokenAddress,
      uint256 _tokenId,
      address _grantor,
      address _grantee
    ) external view returns (bool);
  
    /// @notice Returns the custom data of a role assignment.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user that assigned the role.
    /// @param _grantee The user that received the role.
    function roleData(
      bytes32 _role,
      address _tokenAddress,
      uint256 _tokenId,
      address _grantor,
      address _grantee
    ) external view returns (bytes memory data_);
  
    /// @notice Returns the expiration date of a role assignment.
    /// @param _role The role identifier.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user that assigned the role.
    /// @param _grantee The user that received the role.
    function roleExpirationDate(
      bytes32 _role,
      address _tokenAddress,
      uint256 _tokenId,
      address _grantor,
      address _grantee
    ) external view returns (uint64 expirationDate_);

    /// @notice Checks if the grantor approved the operator for all NFTs.
    /// @param _tokenAddress The token address.
    /// @param _grantor The user that approved the operator.
    /// @param _operator The user that can grant and revoke roles.
    function isRoleApprovedForAll(
      address _tokenAddress,
      address _grantor,
      address _operator
    ) external view returns (bool);

    /// @notice Checks if the grantor approved the operator for a specific NFT.
    /// @param _tokenAddress The token address.
    /// @param _tokenId The token identifier.
    /// @param _grantor The user that approved the operator.
    /// @param _operator The user approved to grant and revoke roles.
    function getApprovedRole(
        address _tokenAddress,
        uint256 _tokenId,
        address _grantor,
        address _operator
    ) external view returns (bool);

}

Metadata extension

The extension builds on the conventional JSON-based NFT metadata schema. To support this feature, dApps must also support the ERC721 or ERC1155 metadata extension. The extension is optional and allows developers to provide additional information about roles.

  1. Roles Metadata extension Provides additional information about roles associated with an NFT. For example, if an NFT has a PROPERTY_MANAGER role, metadata can provide details about that role.

  2. JSON-based metadata schema NFTs typically have JSON metadata containing their name, description, image URL, and other attributes. The Roles Metadata extension expands the existing metadata schema to include role information.

  3. dApp support dApps supporting the Roles Metadata extension must be able to display and handle role information in NFT metadata correctly. Supporting this feature also requires the ERC721 or ERC1155 metadata extension.

The updated metadata schema is as follows.

json
{
  
  /** Existing NFT Metadata **/

  "title": "Asset Metadata",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "Identifies the asset to which this NFT represents"
    },
    "description": {
      "type": "string",
      "description": "Describes the asset to which this NFT represents"
    },
    "image": {
      "type": "string",
      "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive"
    }
  },
  
  /** Additional fields for Roles **/

  "roles": [
    {
      "id": {
        "type": "bytes32",
        "description": "Identifies the role"
      },
      "name": {
        "type": "string",
        "description": "Human-readable name of the role"
      },
      "description": {
        "type": "string",
        "description": "Describes the role"
      },
      "isUniqueRole": {
        "type": "boolean",
        "description": "Whether the role supports simultaneous assignments or not"
      },
      "inputs": [
        {
          "name": {
            "type": "string",
            "description": "Human-readable name of the argument"
          },
          "type": {
            "type": "string",
            "description": "Solidity type, e.g., uint256 or address"
          }
        }
      ]
    }
  ]
  
}

The following JSON illustrates ERC7432 metadata.

json
{
  // ... Existing NFT Metadata
  
  "roles": [
    {
      // keccak256("PROPERTY_MANAGER")
      "id": "0x5cefc88e2d50f91b66109b6bb76803f11168ca3d1cee10cbafe864e4749970c7",
      "name": "Property Manager",
      "description": "The manager of the property is responsible for furnishing it and ensuring its good condition.",
      "isUniqueRole": false,
      "inputs": []
    },
    {
      // keccak256("PROPERTY_TENANT")
      "id": "0x06a3b33b0a800805559ee9c64f55afd8a43a05f8472feb6f6b77484ff5ac9c26",
      "name": "Property Tenant",
      "description": "The tenant of the property is responsible for paying the rent and keeping the property in good condition.",
      "isUniqueRole": true,
      "inputs": [
        {
          "name": "rent",
          "type": "uint256"
        }
      ]
    }
  ]
  
}
  1. Role array properties These properties contain information about NFT roles. Developers may add further information as needed, such as a role's image or a detailed description. It is particularly important to include the isUniqueRole property. The isUniqueRole field indicates whether a role is unique and helps determine whether to call hasRole or hasUniqueRole.

  2. Importance of the inputs property This property describes the information required for a particular operation, such as granting a role. Specifically, it identifies the parameters to encode and pass to grantRole. The inputs property contains type, which specifies each parameter's type, and components, which is used for complex data structures such as tuples. This provides the information needed to perform the operation correctly.

Requirements and notes

  1. Implementing IERC7432 Contracts conforming to this standard must implement the IERC7432 interface. This promotes standardized role management.

  2. Role representation Roles are represented by bytes32 values. Typically, role names are hashed using keccak256, and the hash represents the role. For example, the hash of the ROLE_NAME role is keccak256("ROLE_NAME").

  3. grantRole Grants a role and must revert if _expirationDate is in the past.

  4. grantRoleFrom Must revert if _expirationDate is in the past or msg.sender is not authorized to grant roles on behalf of _grantor.

  5. revokeRole Revokes a role.

  6. revokeRoleFrom Must revert if msg.sender is not authorized to revoke roles on behalf of _revoker.

  7. setRoleApprovalForAll Sets authorization to grant roles.

  8. approveRole Sets role approval permissions.

  9. hasRole Checks whether a role assignment exists and has not expired.

  10. hasUniqueRole Checks whether a role assignment exists, has not expired, and is the most recently granted assignment for that role. It is implemented as a pure or view function; concurrent assignments are not supported for unique roles.

  11. roleData Returns an empty byte array if the role assignment does not exist.

  12. roleExpirationDate Returns 0 if the role assignment does not exist.

  13. isRoleApprovedForAll Returns true if the specified _operator is authorized to grant and revoke roles for all NFTs in the collection on behalf of _grantor.

  14. getApprovedRole Returns true if the specified _operator is authorized to grant and revoke roles for the specified NFT on behalf of _grantor.

  15. ERC165 support Contracts conforming to this standard support ERC165.

Additional notes

ERC7432 is not an extension of ERC721 or ERC1155. It is designed to work across NFT platforms without depending on a particular NFT implementation. The standard can therefore be implemented externally or within the NFT contract itself, allowing dApps to combine immutable NFTs with roles.

Automatic expiration

Automatic expiration is relevant both when granting a role and when checking its validity. grantRole sets the expiration date, while hasRole checks whether the role remains valid. Dates are represented by uint64 rather than uint256. The maximum Unix timestamp corresponds to approximately the year 584,942,417,355, effectively representing forever. The proposal recommends using type(uint64).max when no expiration is intended.

Unique and non-unique roles

The standard supports both unique roles, which can be assigned to only one account at a time, and non-unique roles, which can be assigned to multiple accounts simultaneously. Metadata can specify whether a role is unique or non-unique. If a contract does not implement metadata, all roles are considered non-unique.

Custom data

dApps can use the _data parameter of grantRole to encode role-specific information when assigning a role. This custom data can be retrieved through roleData and is emitted with the RoleGranted event. Developers can integrate it with both on-chain and off-chain applications.

Role approvals

ERC7432 enables users to authorize other accounts to grant and revoke roles. Users can authorize accounts to manage a single NFT or all NFTs in a collection. This allows contracts without ownership of the NFTs to operate through ERC7432.

Backward compatibility

ERC7432 requires the token address (tokenAddress) and token ID (tokenId) to be provided in all relevant functions and events. This allows an independent ERC7432 contract to manage information about NFT roles centrally. The role-management interface therefore does not need to provide other NFT-related functions, such as ownerOf or balanceOf, simplifying integration with different NFT implementations.

Reference implementation

The implementation is available in the following GitHub repository.


roleAssignments

javascript
mapping(address => mapping(address => mapping(address => mapping(uint256 => mapping(bytes32 => RoleData))))) public roleAssignments;

Overview

A mapping storing role assignment information. The role information corresponding to each key is retained.

Details

  • grantor
    • The address of the account granting the role.
  • grantee
    • The address of the account receiving the role.
  • tokenAddress
    • The token contract address.
  • tokenId
    • The token ID.
  • role
    • The hash representing the role.
  • RoleData
    • A struct storing the role's expiration date and custom data.

latestGrantees

javascript
mapping(address => mapping(address => mapping(uint256 => mapping(bytes32 => address)))) public latestGrantees;

Overview

A mapping tracking the latest grantee. It stores the latest grantee for each token and role.

Details

  • grantor
    • The address of the account granting the role.
  • tokenAddress
    • The token contract address.
  • tokenId
    • The token ID.
  • role
    • The hash representing the role.
  • grantee
    • The address of the latest grantee.

tokenIdApprovals

javascript
mapping(address => mapping(address => mapping(uint256 => mapping(address => bool)))) public tokenIdApprovals;

Overview

A mapping tracking operator approvals by token ID.

Details

  • grantor
    • The address of the account granting the role.
  • operator
    • The operator address.
  • tokenAddress
    • The token contract address.
  • isApproved
    • Whether the operator is approved.

tokenApprovals

javascript
mapping(address => mapping(address => mapping(address => bool))) public tokenApprovals;

Overview

A mapping tracking operator approvals by token contract.

Details

  • grantor
    • The address of the account granting the role.
  • operator
    • The operator address.
  • tokenAddress
    • The token contract address.
  • isApproved
    • Whether the operator is approved.

validExpirationDate

javascript
modifier validExpirationDate(uint64 _expirationDate) {
    require(_expirationDate > block.timestamp, "ERC7432: expiration date must be in the future");
    _;
}

Overview A modifier that checks whether the expiration date is in the future.

Details

  • _expirationDate
    • The expiration date to check.

onlyApproved

javascript
modifier onlyApproved(address _tokenAddress, uint256 _tokenId, address _grantor) {
    require(
        isRoleApprovedForAll(_tokenAddress, _grantor, msg.sender) ||
            getApprovedRole(_tokenAddress, _tokenId, _grantor, msg.sender),
        "ERC7432: sender must be approved"
    );
    _;
}

Overview

A modifier that allows a function to execute only if the specified conditions are met. It checks whether the sender is authorized.

Details

  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token ID.
  • _grantor
    • The address of the account granting the role.

grantRole

javascript
function grantRole(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantee,
    uint64 _expirationDate,
    bytes calldata _data
) external {
    _grantRole(_role, _tokenAddress, _tokenId, msg.sender, _grantee, _expirationDate, _data);
}

Overview Grants the specified role (_role) to a grantee (_grantee) for a particular token (_tokenAddress, _tokenId).

Details The role's expiration date (_expirationDate) and custom data (_data) can also be specified.

Parameters

  • _role
    • The identifier of the role to grant.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantee
    • The address receiving the role.
  • _expirationDate
    • The role's expiration date as a Unix timestamp.
  • _data
    • Arbitrary data.

grantRoleFrom

javascript
function grantRoleFrom(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _grantee,
    uint64 _expirationDate,
    bytes calldata _data
) external override onlyApproved(_tokenAddress, _tokenId, _grantor) {
    _grantRole(_role, _tokenAddress, _tokenId, _grantor, _grantee, _expirationDate, _data);
}

Overview Grants the specified role (_role) to a grantee (_grantee) on behalf of the owner (_grantor) of a particular token (_tokenAddress, _tokenId).

Details Authorization from the owner is required.

Parameters

  • _role
    • The identifier of the role to grant.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantor
    • The owner's address granting the role.
  • _grantee
    • The address receiving the role.
  • _expirationDate
    • The role's expiration date as a Unix timestamp.
  • _data
    • Arbitrary data.

_grantRole

javascript
function _grantRole(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _grantee,
    uint64 _expirationDate,
    bytes calldata _data
) internal validExpirationDate(_expirationDate) {
    roleAssignments[_grantor][_grantee][_tokenAddress][_tokenId][_role] = RoleData(_expirationDate, _data);
    latestGrantees[_grantor][_tokenAddress][_tokenId][_role] = _grantee;
    emit RoleGranted( _role, _tokenAddress, _tokenId, _grantor, _grantee, _expirationDate, _data);
}

Overview Performs role assignment and the associated internal processing.

Parameters

  • _role
    • The identifier of the role to grant.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantor
    • The owner's address granting the role.
  • _grantee
    • The address receiving the role.
  • _expirationDate
    • The role's expiration date as a Unix timestamp.
  • _data
    • Arbitrary data.

revokeRole

javascript
function revokeRole(bytes32 _role, address _tokenAddress, uint256 _tokenId, address _grantee) external {
    _revokeRole(_role, _tokenAddress, _tokenId, msg.sender, _grantee);
}

Overview Revokes the specified role (_role) from a grantee (_grantee) for a particular token (_tokenAddress, _tokenId).

Details

  • _role
    • The identifier of the role to revoke.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantee
    • The address of the grantee holding the role.

revokeRoleFrom

javascript
function revokeRoleFrom(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _revoker,
    address _grantee
) external override onlyApproved(_tokenAddress, _tokenId, _revoker) {
    _revokeRole(_role, _tokenAddress, _tokenId, _revoker, _grantee);
}

Overview Revokes the specified role (_role) from a grantee (_grantee) on behalf of the owner (_revoker) of a particular token (_tokenAddress, _tokenId).

Details Authorization from the owner is required.

Parameters

  • _role
    • The identifier of the role to revoke.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _revoker
    • The owner's address revoking the role.
  • _grantee
    • The address of the grantee holding the role.

_revokeRole

javascript
function _revokeRole(
   

 bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _revoker,
    address _grantee
) internal {
    delete roleAssignments[_revoker][_grantee][_tokenAddress][_tokenId][_role];
    delete latestGrantees[_revoker][_tokenAddress][_tokenId][_role];
    emit RoleRevoked(_role, _tokenAddress, _tokenId, _revoker, _grantee);
}

Overview Performs the actual role revocation and associated internal processing.

Details

  • _role
    • The identifier of the role to revoke.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _revoker
    • The owner's address revoking the role.
  • _grantee
    • The address of the grantee holding the role.

hasRole

javascript
function hasRole(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _grantee
) external view returns (bool) {
    return roleAssignments[_grantor][_grantee][_tokenAddress][_tokenId][_role].expirationDate > block.timestamp;
}

Overview Checks whether the grantor (_grantor) of a particular token (_tokenAddress, _tokenId) has assigned the specified role (_role) to a particular grantee (_grantee).

Details

  • _role
    • The identifier of the role to check.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantor
    • The owner's address associated with the role assignment.
  • _grantee
    • The address of the grantee whose role is being checked.

Returns

  • true
    • A bool indicating that the grantee holds the role and it has not expired.
  • false
    • A bool indicating that the grantee does not hold the role or it has expired.

hasUniqueRole

javascript
function hasUniqueRole(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _grantee
) external view returns (bool) {
    return latestGrantees[_grantor][_tokenAddress][_tokenId][_role] == _grantee && roleAssignments[_grantor][_grantee][_tokenAddress][_tokenId][_role].expirationDate > block.timestamp;
}

Overview Checks whether the grantor (_grantor) of a particular token (_tokenAddress, _tokenId) has assigned the specified unique role (_role) to a particular grantee (_grantee).

Details

  • _role
    • The identifier of the role to check.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantor
    • The owner's address associated with the role assignment.
  • _grantee
    • The address of the grantee whose role is being checked.

Parameters None (beyond the parameters described above).

Returns

  • true
    • A bool indicating that the grantee holds the unique role and it has not expired.
  • false
    • A bool indicating that the grantee does not hold the unique role or it has expired.

roleData

javascript
function roleData(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _grantee
) external view returns (bytes memory data_) {
    RoleData memory _roleData = roleAssignments[_grantor][_grantee][_tokenAddress][_tokenId][_role];
    return (_roleData.data);
}

Overview Retrieves data associated with the specified role (_role) assigned to a particular grantee (_grantee) by the grantor (_grantor) of a token (_tokenAddress, _tokenId).

Details

  • _role
    • The identifier of the role whose data is requested.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantor
    • The owner's address associated with the role assignment.
  • _grantee
    • The address of the grantee whose data is requested.

Returns

  • data_
    • Data associated with the role.

roleExpirationDate

javascript
function roleExpirationDate(
    bytes32 _role,
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _grantee
) external view returns (uint64 expirationDate_){
    RoleData memory _roleData = roleAssignments[_grantor][_grantee][_tokenAddress][_tokenId][_role];
    return (_roleData.expirationDate);
}

Overview Retrieves the expiration date of the specified role (_role) assigned to a particular grantee (_grantee) by the grantor (_grantor) of a token (_tokenAddress, _tokenId).

Details

  • _role
    • The identifier of the role whose expiration date is requested.
  • _tokenAddress
    • The token contract address.
  • _tokenId
    • The token identifier.
  • _grantor
    • The owner's address associated with the role assignment.
  • _grantee
    • The address of the grantee whose role expiration date is requested.

Returns

  • expirationDate_
    • The role's expiration date as a Unix timestamp.

supportsInterface

javascript
function supportsInterface(bytes4 interfaceId) external view virtual override returns (bool) {
    return interfaceId == type(IERC7432).interfaceId;
}

Overview Checks whether the specified interface is supported. It is used to check support for a particular interface, such as IERC7432.

Details Used to check support for a particular interface, such as IERC7432.

Parameters

  • interfaceId
    • The identifier of the interface to check.

Returns

  • true
    • The specified interface is supported.
  • false
    • The specified interface is not supported.

setRoleApprovalForAll

javascript
function setRoleApprovalForAll(
    address _tokenAddress,
    address _operator,
    bool _isApproved
) external override {
    tokenApprovals[msg.sender][_tokenAddress][_operator] = _isApproved;
    emit RoleApprovalForAll(_tokenAddress, _operator, _isApproved);
}

Overview Allows the owner to grant or revoke role approval for a particular operator (_operator) across the specified token collection (_tokenAddress).

Parameters

  • _tokenAddress
    • The token contract address for which role approval is granted or revoked.
  • _operator
    • The address of the operator whose role approval is granted or revoked.
  • _isApproved
    • true to grant role approval, false to revoke it.

approveRole

javascript
function approveRole(
    address _tokenAddress,
    uint256 _tokenId,
    address _operator,
    bool _approved
) external override {
    tokenIdApprovals[msg.sender][_tokenAddress][_tokenId][_operator] = _approved;
    emit RoleApproval(_tokenAddress, _tokenId, _operator, _approved);
}

Overview Allows the owner to grant or revoke role approval for a particular operator (_operator) for the specified token (_tokenAddress, _tokenId).

Parameters

  • _tokenAddress
    • The token contract address for which role approval is granted or revoked.
  • _tokenId
    • The identifier of the token for which role approval is granted or revoked.
  • _operator
    • The address of the operator whose role approval is granted or revoked.
  • _approved
    • true to grant role approval, false to revoke it.

isRoleApprovedForAll

javascript
function isRoleApprovedForAll(
    address _tokenAddress,
    address _grantor,
    address _operator
) public view override returns (bool) {
    return tokenApprovals[_grantor][_tokenAddress][_operator];
}

Overview Checks whether the owner has granted role approval to a particular operator (_operator) across the specified token collection (_tokenAddress).

Parameters

  • _tokenAddress
    • The token contract address for which role approval is checked.
  • _grantor
    • The address of the owner who granted role approval.
  • _operator
    • The address of the operator whose role approval is checked.

Returns

  • true
    • Role approval is granted.
  • false
    • Role approval is not granted.

getApprovedRole

javascript
function getApprovedRole(
    address _tokenAddress,
    uint256 _tokenId,
    address _grantor,
    address _operator
) public view override returns (bool) {
    return tokenIdApprovals[_grantor][_tokenAddress][_tokenId][_operator];
}

Overview Checks whether the owner has granted role approval to a particular operator (_operator) for the specified token (_tokenAddress, _tokenId).

Parameters

  • _tokenAddress
    • The token contract address for which role approval is checked.
  • _tokenId
    • The identifier of the token for which role approval is checked.
  • _grantor
    • The address of the owner who granted role approval.
  • _operator
    • The address of the operator whose role approval is checked.

Returns

  • true
    • Role approval is granted.
  • false
    • Role approval is not granted.

Security considerations

Developers integrating the NFT roles interface should consider the following points.

  • Enforce appropriate access controls
    • Implement appropriate access control mechanisms to prevent unauthorized role assignments and revocations.
    • This prevents unauthorized operations and improves security.
  • Consider security measures
    • When implementing smart contracts, consider potential attacks such as reentrancy and implement appropriate countermeasures.
    • Ensuring security is essential.
  • Verify NFT ownership
    • Because ERC7432 does not automatically verify NFT ownership, the dApp is responsible for explicitly querying the NFT owner and passing the correct owner (_grantor) to hasRole.
    • This helps ensure that the role assignment is valid for the owner.
  • Check whether roles are unique or non-unique
    • The dApp is responsible for determining whether a role is unique (assignable to only one account at a time) or non-unique (assignable to multiple accounts simultaneously).
    • For unique roles, use hasUniqueRole to confirm that the role has not been assigned to another account.

Citation

Ernani São Thiago (@ernanirst), Daniel Lima (@karacurt), "ERC-7432: Non-Fungible Token Roles [DRAFT]," Ethereum Improvement Proposals, no. 7432, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7432.

Conclusion

This article examined ERC7432, which proposes an interface for managing various roles associated with NFTs.