Question about roles.sol

I’m running this contract on remix https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/roles/WhitelistAdminRole.sol

There was no error but i saw an warning “Gas requirement of function addWhitelistAdmin(address) high: infinite.If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage)”.

What can i do to turn the warning off ?

1 Like

Hi @Sotatek-PhuongNguyen,

Welcome to the community :wave:

The reason for the message is that you are attempting to call addWhitelistAdmin from an account that isn’t a Whitelist admin and the transaction would revert.

If you run Remix using JavaScript VM (rather than InjectedWeb3) and you try to add addWhitelistAdmin from an account that isn’t a Whitelist admin (you can just call renounceWhitelistAdmin first) then the transaction will revert with the reason "WhitelistAdminRole: caller does not have the WhitelistAdmin role"

The function addWhitelistAdmin has a modifier onlyWhitelistAdmin.

    function addWhitelistAdmin(address account) public onlyWhitelistAdmin {
        _addWhitelistAdmin(account);
    }

This modifier checks that the caller (msg.sender) is an admin and reverts if it isn’t.

    modifier onlyWhitelistAdmin() {
        require(isWhitelistAdmin(msg.sender), "WhitelistAdminRole: caller does not have the WhitelistAdmin role");
        _;
    }

Note: You should only use code published in an official release of OpenZeppelin Contracts, the latest release is 2.3. When importing via GitHub on Remix you can specify the release tag, (otherwise you will get the latest code in the master branch).
For example:

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/token/ERC20/ERC20.sol";
1 Like

Hi @Sotatek-PhuongNguyen,

Feel free to ask all the questions that you need.

If you have a moment it would be great if you could Introduce yourself here!