Skip to content
Lattice

IAccessControl

Git Source

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

NameTypeDescription
rolebytes32The role identifier to verify.
accountaddressThe account address to check.

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
rolebytes32The role identifier to query.

Returns

NameTypeDescription
<none>bytes32bytes32 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

NameTypeDescription
rolebytes32The role identifier to grant.
accountaddressThe 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

NameTypeDescription
rolebytes32The role identifier to revoke.
accountaddressThe 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

NameTypeDescription
rolebytes32The role identifier to renounce.
callerConfirmationaddressThe 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

NameTypeDescription
rolebytes32The role identifier whose admin has changed.
previousAdminRolebytes32The previous admin role for this role.
newAdminRolebytes32The 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

NameTypeDescription
rolebytes32The role identifier that was granted.
accountaddressThe account that received the role.
senderaddressThe 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

NameTypeDescription
rolebytes32The role identifier that was revoked.
accountaddressThe account that lost the role.
senderaddressThe 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

NameTypeDescription
accountaddressThe account that lacks authorization.
neededRolebytes32The 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();