Help making a blacklist on ERC20

Hi, I'm trying to make a Blacklist on a smart contract. I read the different questions over here and seems the way is to use AccessControl, so far everything was ok until here.

However, when I create a contract in openzeppelin's "wizard", the image on the left tells me to restrict access by passing the "onlyRole()" modifier to the functions, but if I go to its documentation on the use of "AccessControl" it tells me that use a require(hasRole(role, msg.sender)), "string"

My doubt is if there would be a big difference between using one or the other, beyond the error message that would be "you are not this user" or the message that you want to put. Which is a better practice?

And the second doubt is that how could be a example to create it using AccessControl. I just can found this example. It is posible to use " !BlockedUser" as a modifier?

The onlyRole modifier wasn't present in AccessControl initially and the documentation was written before that.

onlyRole will not be useful for impementing a blacklist role though, because you want the opposite of "only role".

You could do something like this:

bytes32 BLACKLIST_ROLE = keccak256('BLACKLIST_ROLE');

function foo() {
  require(!hasRole(BLACKLIST_ROLE, msg.sender));
}
1 Like