Problem with the DEFAULT_ADMIN_ROLE

When deploying the smart contract everything works fine. Then i try to grantRole but it wont work unless an admin does it. Then i check the address for DEFAULT_ADMIN_ROLE and it is still the 0x00 address..

My constructor has the following line of code to set the deployer as admin:

_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);

I am using Remix version 0.8.3 and i have imported access control from the master branch at:

Please help me.

Hi, welcome! :wave:

Yeah, I think your way is correct, and I deployed a contract, it seems like it worked well.

image

image

You can have a look at the above, DEFAULT_ADMIN_ROLE = 0x00; and the deployer account is 0x5B38, so when call hasRole() with 0x5B38, it returns true; when call hasRole() with a common user account 0xf8e8, it returns false.

Ohhh, I see, you mean why DEFAULT_ADMIN_ROLE is 0x00, right? Cause it is defined in the contract, you can have a look at this line:
openzeppelin-contracts/AccessControl.sol at master · OpenZeppelin/openzeppelin-contracts (github.com)

Hi @Skyge

What i am trying to do is setting the deployment address to have the default admin role in the constructor. I want to be able to grant roles when the contract is deployed but it seems it doesnt change. Is there something i am missing?

Edit: Must have been something yesterday. When running the code today and re-deploying, i can now grantRole without problems! But thx for the help, good to know that the Byte32 for the admin is static 0x00!

1 Like