Skip to main content

Access Control Batch Grant Module

Provides an internal function for granting roles to multiple accounts in a single transaction

Key Features
  • Internal functions for composability within facets.
  • Efficient batch granting of roles to multiple accounts.
  • Utilizes diamond storage for shared state management.
  • No external dependencies, promoting a self-contained design.

Storage

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol"))

Access Control Storage

Definition
/** storage-location: erc8042:compose.accesscontrol */
struct AccessControlStorage {
mapping(address account => mapping(bytes32 role => bool hasRole)) hasRole;
mapping(bytes32 role => bytes32 adminRole) adminRole;
}

Functions

getStorage

Returns the storage for the Access Control.

function getStorage() pure returns (AccessControlStorage storage _s);

Returns:

PropertyTypeDescription
_sAccessControlStorageThe storage for the AccessControl.

grantRoleBatch

function to grant a role to multiple accounts in a single transaction. Emits a RoleGranted event for each newly granted account. Reverts with AccessControlUnauthorizedAccount if the caller is not the admin of the role.

function grantRoleBatch(bytes32 _role, address[] calldata _accounts) ;

Parameters:

PropertyTypeDescription
_rolebytes32The role to grant.
_accountsaddress[]The accounts to grant the role to.

Events

Errors

Best Practices

  • Ensure the caller has the necessary permissions to grant roles before invoking grantRoleBatch.
  • Consider the gas implications for very large _accounts arrays; for extremely large lists, multiple calls might be more gas-efficient.
Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.