Skip to main content

Access Control Batch Grant Facet

Exposes an external function to grant a specific role to multiple accounts efficiently within a single transaction.

Key Features
  • Grants roles to multiple accounts in a single atomic operation.
  • Emits RoleGranted events for each account granted a role.
  • Uses diamond storage for role management, ensuring state consistency across facets.
  • Provides exportSelectors for easy integration into diamond upgrade processes.

Storage

State Variables

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

AccessControlStorage

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

Functions

grantRoleBatch

Grants 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) external;

Parameters:

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

Events

Errors

Best Practices

  • Ensure the caller has the necessary admin privileges to grant the specified role.
  • 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.