Inheriting from Openzeppelin whitelistedRole, is there a way to count the number of accounts currently whitelisted?

I have a function in mind which would distribute a certain amount of tokens evenly to the whitelisted addresses. The amount transferred to each account would depend on the number of whitelisted accounts. I understand from other questions that getting an array of the whitelisted accounts is not really feasible, but for the above purpose that hopefully should not be necessary (?).

Is this doable, and if so where would be best to start?

1 Answer 1


An event is fired when an address is whitelisted or remove.

function _addWhitelisted(address account) internal {
    emit WhitelistedAdded(account);

function _removeWhitelisted(address account) internal {
    emit WhitelistedRemoved(account);

You could scan for these events for the contract in question. You should be able to get all the addresses that were whitelisted or removed. How to scan for past events depends on the library you use, so I can't give you a specific example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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