What is the has() function in Solidity?

  struct Role {
    mapping (address => bool) bearer;

  function add(Role storage role, address account) internal {
    require(account != address(0), "The account cannot be an uninitialized address");
    require(!has(role, account)); // right here

    role.bearer[account] = true;

Intuitively, I think it's determining whether the account exists in role or not and returning a boolean value, but can't seem to find the documentation.


It's not part of Solidity, you are probable inheriting from the access control in the OpenZeppelin contracts: https://docs.openzeppelin.com/contracts/2.x/api/access#Roles-has-struct-Roles-Role-address-. In v3 it's called hasRole.

See full documentation at: https://docs.openzeppelin.com/contracts/2.x/access-control#using-roles.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.