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 ERC-7589, which proposes a mechanism for managing roles associated with semi-fungible tokens (SFTs).
This article translates, summarizes, and expands on the proposal below, as discussed in the original article published on July 7, 2024.
I have also written about various other EIPs.
Overview
The standard proposes role management for semi-fungible tokens (SFTs).
Semi-fungible tokens (SFTs), such as those represented by ERC-1155, combine characteristics of ERC-20 and ERC-721 tokens.
ERC-1155 supports a tokenId like ERC-721, while allowing multiple units of the same tokenId to be issued, much like fungible ERC-20 tokens.
Each role assignment is granted to a single address and automatically becomes invalid when it expires. Roles are represented by identifiers of type bytes32, and the standard defines a customizable variable-length data field called _data.
For more on ERC-20, see the following article.
For more on ERC-721, see the following article.
For more on ERC-1155, see the following article.
Motivation
ERC-1155 made an important contribution to tokenization on Ethereum by allowing developers to create tokens with both fungible and non-fungible characteristics within a single contract. Although ERC-1155 is well suited to tracking token ownership, it focuses primarily on token balances rather than how tokens can be used.
Access control is essential to managing token usage. It determines who has permission to use a token and, depending on the permissions involved, can even grant complete control over an owner's balance.
For example, an application might allow users to execute a particular function only if they hold at least a specified number of tokens.
Delegating permissions to other users enables more complex use cases. A game, for example, could issue in-game items through a single ERC-1155 contract and lend those items to other players through a secure role management interface.
Specification
Contracts implementing this standard must implement the following interface.
/// @title ERC-7589 Semi-Fungible Token Roles
/// @dev See https://eips.ethereum.org/EIPS/eip-7589
/// Note: the ERC-165 identifier for this interface is 0xc4c8a71d.
interface IERC7589 /* is IERC165 */ {
/** Events **/
/// @notice Emitted when tokens are committed (deposited or frozen).
/// @param _grantor The owner of the SFTs.
/// @param _commitmentId The identifier of the commitment created.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _tokenAmount The token amount.
event TokensCommitted(
address indexed _grantor,
uint256 indexed _commitmentId,
address indexed _tokenAddress,
uint256 _tokenId,
uint256 _tokenAmount
);
/// @notice Emitted when a role is granted.
/// @param _commitmentId The commitment identifier.
/// @param _role The role identifier.
/// @param _grantee The recipient the role.
/// @param _expirationDate The expiration date of the role.
/// @param _revocable Whether the role is revocable or not.
/// @param _data Any additional data about the role.
event RoleGranted(
uint256 indexed _commitmentId,
bytes32 indexed _role,
address indexed _grantee,
uint64 _expirationDate,
bool _revocable,
bytes _data
);
/// @notice Emitted when a role is revoked.
/// @param _commitmentId The commitment identifier.
/// @param _role The role identifier.
/// @param _grantee The recipient of the role revocation.
event RoleRevoked(uint256 indexed _commitmentId, bytes32 indexed _role, address indexed _grantee);
/// @notice Emitted when a user releases tokens from a commitment.
/// @param _commitmentId The commitment identifier.
event TokensReleased(uint256 indexed _commitmentId);
/// @notice Emitted when a user is approved to manage roles 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);
/** External Functions **/
/// @notice Commits tokens (deposits on a contract or freezes balance).
/// @param _grantor The owner of the SFTs.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _tokenAmount The token amount.
/// @return commitmentId_ The unique identifier of the commitment created.
function commitTokens(
address _grantor,
address _tokenAddress,
uint256 _tokenId,
uint256 _tokenAmount
) external returns (uint256 commitmentId_);
/// @notice Grants a role to `_grantee`.
/// @param _commitmentId The identifier of the commitment.
/// @param _role The role identifier.
/// @param _grantee The recipient the role.
/// @param _expirationDate The expiration date of the role.
/// @param _revocable Whether the role is revocable or not.
/// @param _data Any additional data about the role.
function grantRole(
uint256 _commitmentId,
bytes32 _role,
address _grantee,
uint64 _expirationDate,
bool _revocable,
bytes calldata _data
) external;
/// @notice Revokes a role.
/// @param _commitmentId The commitment identifier.
/// @param _role The role identifier.
/// @param _grantee The recipient of the role revocation.
function revokeRole(uint256 _commitmentId, bytes32 _role, address _grantee) external;
/// @notice Releases tokens back to grantor.
/// @param _commitmentId The commitment identifier.
function releaseTokens(uint256 _commitmentId) external;
/// @notice Approves operator to grant and revoke 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;
/** View Functions **/
/// @notice Returns the owner of the commitment (grantor).
/// @param _commitmentId The commitment identifier.
/// @return grantor_ The commitment owner.
function grantorOf(uint256 _commitmentId) external view returns (address grantor_);
/// @notice Returns the address of the token committed.
/// @param _commitmentId The commitment identifier.
/// @return tokenAddress_ The token address.
function tokenAddressOf(uint256 _commitmentId) external view returns (address tokenAddress_);
/// @notice Returns the identifier of the token committed.
/// @param _commitmentId The commitment identifier.
/// @return tokenId_ The token identifier.
function tokenIdOf(uint256 _commitmentId) external view returns (uint256 tokenId_);
/// @notice Returns the amount of tokens committed.
/// @param _commitmentId The commitment identifier.
/// @return tokenAmount_ The token amount.
function tokenAmountOf(uint256 _commitmentId) external view returns (uint256 tokenAmount_);
/// @notice Returns the custom data of a role assignment.
/// @param _commitmentId The commitment identifier.
/// @param _role The role identifier.
/// @param _grantee The recipient the role.
/// @return data_ The custom data.
function roleData(
uint256 _commitmentId,
bytes32 _role,
address _grantee
) external view returns (bytes memory data_);
/// @notice Returns the expiration date of a role assignment.
/// @param _commitmentId The commitment identifier.
/// @param _role The role identifier.
/// @param _grantee The recipient the role.
/// @return expirationDate_ The expiration date.
function roleExpirationDate(
uint256 _commitmentId,
bytes32 _role,
address _grantee
) external view returns (uint64 expirationDate_);
/// @notice Returns the expiration date of a role assignment.
/// @param _commitmentId The commitment identifier.
/// @param _role The role identifier.
/// @param _grantee The recipient the role.
/// @return revocable_ Whether the role is revocable or not.
function isRoleRevocable(
uint256 _commitmentId,
bytes32 _role,
address _grantee
) external view returns (bool revocable_);
/// @notice Checks if the grantor approved the operator for all SFTs.
/// @param _tokenAddress The token address.
/// @param _grantor The user that approved the operator.
/// @param _operator The user that can grant and revoke roles.
/// @return isApproved_ Whether the operator is approved or not.
function isRoleApprovedForAll(
address _tokenAddress,
address _grantor,
address _operator
) external view returns (bool isApproved_);
}The term commit in this standard refers to either of the following operations.
-
Deposit
- Deposit tokens into a designated smart contract.
- The tokens are transferred from their owner to the smart contract and cannot be withdrawn until specified conditions are met.
-
Freeze
- Temporarily prevent the tokens from being used.
- The tokens remain at the owner's address, but their use or
transferis restricted until specified conditions are met.
Events
TokensCommitted
Emitted when tokens are committed, whether by depositing or freezing them. Records the grantor, commitment ID, token contract address, token ID, and token amount.
RoleGranted
Emitted when a role is granted. Records the commitment ID, role ID, grantee address, expiration date, whether the role is revocable, and additional data.
RoleRevoked
Emitted when a role is revoked. Records the commitment ID, role ID, and address from which the role was revoked.
TokensReleased
Emitted when tokens are released from a commitment. Records the commitment ID.
RoleApprovalForAll
Emitted when another user's permission to manage roles is granted or revoked. Records the token contract address, the approved user, and the approval status.
State-changing functions
commitTokens
Commits tokens by depositing or freezing them. Takes the grantor, token contract address, token ID, and token amount as arguments, and returns the commitment ID.
grantRole
Grants a role to an address. Takes the commitment ID, role ID, grantee address, expiration date, revocability flag, and additional data.
revokeRole
Revokes a role. Takes the commitment ID, role ID, and address from which the role is being revoked.
releaseTokens
Returns committed tokens to the grantor. Takes the commitment ID.
setRoleApprovalForAll
Grants or revokes another user's permission to manage roles. Takes the token contract address, the user whose approval is being set, and the approval status.
View functions
grantorOf
Returns the owner (grantor) of a commitment. Takes the commitment ID.
tokenAddressOf
Returns the contract address of the committed tokens. Takes the commitment ID.
tokenIdOf
Returns the ID of the committed tokens. Takes the commitment ID.
tokenAmountOf
Returns the amount of committed tokens. Takes the commitment ID.
roleData
Returns the custom data associated with a role assignment. Takes the commitment ID, role ID, and grantee address.
roleExpirationDate
Returns the expiration date of a role assignment. Takes the commitment ID, role ID, and grantee address.
isRoleRevocable
Returns whether a role can be revoked. Takes the commitment ID, role ID, and grantee address.
isRoleApprovedForAll
Returns whether a particular user has permission to manage roles for all of the relevant SFTs. Takes the token contract address, grantor, and approved user.
Single-transaction extension
Granting a role through the core interface requires two transactions. The first commits the tokens, and the second grants the role. Implementing the following extension allows users to commit tokens and grant a role in a single transaction.
/// @title ERC-7589 Semi-Fungible Token Roles, optional single transaction extension
/// @dev See https://eips.ethereum.org/EIPS/eip-7589
/// Note: the ERC-165 identifier for this interface is 0x5c3d7d74.
interface ICommitTokensAndGrantRoleExtension /* is IERC7589 */ {
/// @notice Commits tokens and grant role in a single transaction.
/// @param _grantor The owner of the SFTs.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _tokenAmount The token amount.
/// @param _role The role identifier.
/// @param _grantee The recipient the role.
/// @param _expirationDate The expiration date of the role.
/// @param _revocable Whether the role is revocable or not.
/// @param _data Any additional data about the role.
/// @return commitmentId_ The identifier of the commitment created.
function commitTokensAndGrantRole(
address _grantor,
address _tokenAddress,
uint256 _tokenId,
uint256 _tokenAmount,
bytes32 _role,
address _grantee,
uint64 _expirationDate,
bool _revocable,
bytes calldata _data
) external returns (uint256 commitmentId_);
}commitTokensAndGrantRole
Commits tokens and grants a role in a single transaction.
- Parameters
_grantor- The SFT owner.
_tokenAddress- The token contract address.
_tokenId- The token identifier.
_tokenAmount- The amount of tokens.
_role- The role identifier.
_grantee- The address receiving the role.
_expirationDate- The role's expiration date.
_revocable- Whether the role can be revoked.
_data- Additional data associated with the role.
- Return value:
commitmentId_- The identifier of the newly created commitment.
Role balance extension
/// @title ERC-7589 Semi-Fungible Token Roles, optional role balance extension
/// @dev See https://eips.ethereum.org/EIPS/eip-7589
/// Note: the ERC-165 identifier for this interface is 0x2f35b73f.
interface IRoleBalanceOfExtension /* is IERC7589 */ {
/// @notice Returns the sum of all tokenAmounts granted to the grantee for the given role.
/// @param _role The role identifier.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _grantee The user for which the balance is returned.
/// @return balance_ The balance of the grantee for the given role.
function roleBalanceOf(
bytes32 _role,
address _tokenAddress,
uint256 _tokenId,
address _grantee
) external returns (uint256 balance_);
}The core interface allows callers to retrieve the balance of committed tokens for a commitment, but it does not provide a way to retrieve a particular user's aggregate committed balance. This extension allows callers to retrieve the balance of a particular token associated with a user's role assignments.
Although useful for certain use cases, the extension may increase implementation complexity.
roleBalanceOf
Returns a particular user's total token balance associated with the specified role.
- Parameters
_role- The role identifier.
_tokenAddress- The token contract address.
_tokenId- The token identifier.
_grantee- The user whose balance is being queried.
- Return value:
balance_- The user's total token balance associated with the specified role.
Metadata extension
This extension builds on the existing JSON-based metadata schema for SFTs. It allows role information to be included in token metadata, and decentralized applications (DApps) using ERC-1155 need to implement it when supporting this metadata functionality.
{
/** Existing ERC-1155 Metadata **/
"title": "Token Metadata",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Identifies the asset to which this token represents"
},
"decimals": {
"type": "integer",
"description": "The number of decimal places that the token amount should display - e.g. 18, means to divide the token amount by 1000000000000000000 to get its user representation."
},
"description": {
"type": "string",
"description": "Describes the asset to which this token represents"
},
"image": {
"type": "string",
"description": "A URI pointing to a resource with mime type image/* representing the asset to which this token represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."
},
"properties": {
"type": "object",
"description": "Arbitrary properties. Values may be strings, numbers, object or arrays."
}
},
/** Additional fields for ERC-7589 **/
"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"
},
"inputs": [{
"name": {
"type": "string",
"description": "Human-readable name of the argument"
},
"type": {
"type": "string",
"description": "Solidity type, e.g., uint256 or address"
}
}]
}]
}The following is an example.
{
/** Existing ERC-1155 Metadata **/
"name": "Asset Name",
"description": "Lorem ipsum...",
"image": "https:\/\/s3.amazonaws.com\/your-bucket\/images\/{id}.png",
"properties": {
"simple_property": "example value",
"rich_property": {
"name": "Name",
"value": "123",
"display_value": "123 Example Value",
"class": "emphasis",
"css": {
"color": "#ffffff",
"font-weight": "bold",
"text-decoration": "underline"
}
},
"array_property": {
"name": "Name",
"value": [1,2,3,4],
"class": "emphasis"
}
},
/** Additional fields for ERC-7589 **/
"roles": [
{
// keccak256("Player(uint256)")
"id": "0x70d2dab8c6ff873dc0b941220825d9271fdad6fdb936f6567ffde77d05491cef",
"name": "Player",
"description": "The user allowed to use this item in-game.",
"inputs": [
{
"name": "ProfitShare",
"type": "uint256"
}
]
}
]
}The properties of the roles array are recommended. Developers should add other information relevant to their use cases, such as an image for each role.
The inputs property describes the parameters that should be encoded and passed to the grantRole function. It may contain a type property describing the data format and components.
Using the property types and components defined by the Solidity ABI specification is recommended.
For the Solidity ABI specification, see the official documentation below.
Implementation requirements
The following considerations apply when implementing a contract that conforms to the standard.
Basic requirements
-
Required interface
- Contracts must implement the
IERC7589interface.
- Contracts must implement the
-
Role identifiers
- Every role is represented by a
bytes32identifier. - Using the
keccak256hash of the role name and its arguments as the identifier is recommended. - Example
keccak256("Player(uint256)")
- Every role is represented by a
commitTokens function
The commitTokens function commits tokens by depositing or freezing them. It must revert if the required conditions are not met. The _tokenAmount must be nonzero, and msg.sender must be authorized by the _grantor.
grantRole function
The grantRole function grants a specified role to a specified address. It must revert if _expirationDate is in the past or if msg.sender is not authorized to grant roles on behalf of the grantor.
For permanent roles, using type(uint64).max is recommended.
revokeRole function
The revokeRole function revokes a previously granted role. The function should always allow the grantee to revoke their own role.
The function must revert if the role assignment does not exist, if msg.sender is not authorized by either the grantor or the grantee, or if msg.sender is the grantor or an authorized representative of the grantor but the role is neither revocable nor expired.
releaseTokens function
The releaseTokens function returns committed tokens to the grantor.
It must revert if the commitment does not exist, if msg.sender is not authorized by the grantor, or if at least one non-revocable role associated with the commitment has not yet expired.
Please note that “approval” refers to allowing users to commit tokens and grant/revoke roles on one’s behalf. An approved user either received the role approval or is the target user. Role approvals are not to be confused with ERC-1155 approvals. More information can be found in the Role Approvals section.
In other words, “approve” means authorizing someone to commit tokens and grant or revoke roles on your behalf. An approved user either has role approval or is the relevant user themselves. Role approvals must not be confused with ERC-1155
approvepermissions. ...
Additional considerations
Theoretical background
A token commitment provides a mechanism for delegating control over semi-fungible tokens (SFTs). It represents either a frozen balance or tokens deposited in a contract, allowing an SFT owner to delegate the use of those assets to another address.
What distinguishes ERC-7589
ERC-7589 is not an extension of ERC-1155. This keeps the standard independent of a particular implementation. It can therefore be implemented in an external contract or in the same contract as the SFT itself, allowing greater flexibility.
Role approvals
ERC-7589 allows users to authorize operators to grant and revoke roles. This is important for interoperability because third-party applications do not need custody-level approvals to manage users' roles.
Role approval is part of the core interface, and compliant contracts must implement the setRoleApprovalForAll and isRoleApprovedForAll functions.
Automatic expiration
Automatic expiration saves users gas. Rather than requiring users to call revokeRole whenever a role assignment ends, applications should call roleExpirationDate and compare the returned value with the current timestamp to determine whether the role is still valid.
In ERC-7589, dates are represented as uint64 values. The largest UNIX timestamp representable by a uint64 is approximately 584 billion years, which is long enough to be treated as permanent. Accordingly, type(uint64).max represents a role that never expires in practice.
Revocable roles
In some situations, the grantor needs to be able to revoke a role before it expires. In others, the grantee needs a guarantee that the role will not be revoked early, for example when the grantee pays to use the tokens.
For this reason, the grantRole function includes the _revocable parameter, which determines whether the grantor can revoke a role before its expiration date.
Regardless of the value of _revocable, the grantee can always revoke their own role, allowing the recipient to remove unwanted assignments.
Custom data
The _data parameter of the grantRole function is an important part of the design. SFTs have many possible use cases, and covering all of them through Solidity-level interfaces is impractical. A generic parameter of type bytes allows arbitrary custom information to be supplied when granting a role.
For example, a Web3 game might delegate an NFT to a player and introduce a revenue-sharing mechanism represented by a uint256 value.
With ERC-7589, the uint256 value can be encoded as bytes and passed to the grantRole function. The data can be validated on-chain or off-chain, and other contracts can query it through the roleData function.
Compatibility
Many SFT contracts are deployed without an upgrade mechanism. This raises the question of how role management can be introduced for those SFTs.
The proposal allows the token contract to be identified through the tokenAddress parameter when committing tokens. Developers can choose to implement ERC-7589 within the SFT contract itself or entrust role management to a trusted external contract.
Implementation
The reference implementation is available at the following link.
https://eips.ethereum.org/assets/eip-7589/ERC7589.sol
Security
When integrating SFTs with this standard, the following considerations are important.
- Ensure that appropriate access controls are in place to prevent unauthorized role assignments and revocations.
- This is particularly important when committing and releasing tokens.
- Consider potential attacks, including reentrancy, and ensure that appropriate safeguards, such as
ReentrancyGuard, are implemented. - Always check expiration dates before allowing users to exercise the permissions associated with a role assignment.
Citation
Ernani São Thiago (@ernanirst), Daniel Lima (@karacurt), "ERC-7589: Semi-Fungible Token Roles [DRAFT]," Ethereum Improvement Proposals, no. 7589, December 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7589.
Final thoughts
This article covered ERC-7589 and its proposed mechanism for managing roles associated with semi-fungible tokens (SFTs).
If you have questions, feel free to send me a direct message on Twitter.
I also publish content on other platforms.



