IAccessControl
Title: IAccessControl
Author: Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/IAccessControl.sol)
External interface of AccessControl declared to support ERC-165 detection.
Functions
hasRole
Checks whether an account has been granted a specific role.
function hasRole(bytes32 role, address account) external view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier to verify. |
| account | address | The account address to check. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool | bool True if the account has the role, false otherwise. |
getRoleAdmin
Retrieves the admin role that controls access to a specific role.
function getRoleAdmin(bytes32 role) external view returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier to query. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 | bytes32 The admin role that can grant or revoke the specified role. To change a role's admin, use AccessControl._setRoleAdmin. |
grantRole
Grants a role to an account.
Emits a RoleGranted event if the account didn't already hold the role. Requirements:
- the caller must have the admin role for the target role.
function grantRole(bytes32 role, address account) external;Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier to grant. |
| account | address | The account address to grant the role to. |
revokeRole
Revokes a role from an account.
Emits a RoleRevoked event if the account currently holds the role. Requirements:
- the caller must have the admin role for the target role.
function revokeRole(bytes32 role, address account) external;Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier to revoke. |
| account | address | The account address to revoke the role from. |
renounceRole
Renounces a role from the calling account.
Allows accounts to lose privileges if compromised (e.g., misplaced keys or compromised devices). Emits a RoleRevoked event if the caller currently holds the role. Requirements:
- the caller's actual address must match the callerConfirmation parameter for security.
function renounceRole(bytes32 role, address callerConfirmation) external;Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier to renounce. |
| callerConfirmation | address | The caller's address as a confirmation parameter. |
Events
RoleAdminChanged
Emitted when a new admin role is assigned to govern access for another role. The DEFAULT_ADMIN_ROLE is the initial admin for all roles, though RoleAdminChanged is not emitted for this initial state.
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier whose admin has changed. |
| previousAdminRole | bytes32 | The previous admin role for this role. |
| newAdminRole | bytes32 | The new admin role for this role. |
RoleGranted
Emitted when a role is granted to an account. The sender is the account that initiated the grant operation (typically the admin). Expected when using the internal AccessControl._grantRole function.
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier that was granted. |
| account | address | The account that received the role. |
| sender | address | The account that originated the contract call (admin role bearer). |
RoleRevoked
Emitted when a role is revoked from an account. The sender varies based on the revocation method:
- if using
revokeRole, sender is the admin role bearer - if using
renounceRole, sender is the role bearer (i.e., the account losing the role)
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);Parameters
| Name | Type | Description |
|---|---|---|
| role | bytes32 | The role identifier that was revoked. |
| account | address | The account that lost the role. |
| sender | address | The account that originated the contract call (admin or account itself). |
Errors
AccessControlUnauthorizedAccount
Thrown when an account is missing a required role.
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | The account that lacks authorization. |
| neededRole | bytes32 | The role identifier that the account is missing. |
AccessControlBadConfirmation
Thrown when function caller confirmation fails during role renunciation. This prevents accidental role loss due to incorrect address parameter.
NOTE: Don't confuse with AccessControlUnauthorizedAccount.
error AccessControlBadConfirmation();