0

I have a value that is bytes32 private constant ADMIN = keccak256(abi.encodePacked("ADMIN"));

so a value is stored in the ADMIN which is byte32 what i want a way by which i can display in frontend what value is stored in bytes32

I need multiple permessions level in my website so i want the admin have the permession that they can mint roles once they mint it can be assigned to a address which is done but just need a way by which i can get the bytes32 value

sarangkkl
  • 129
  • 1
  • 8

1 Answers1

2

You might not understand what's happening here. This code:

bytes32 private constant ADMIN = keccak256(abi.encodePacked("ADMIN"));

Is just a keccak256 hash of a string. Libraries like this will use the hashes to serve as keys for mappings.

So yes, you can display the data on the frontend easily. In Ethers, for example (here's a useful source about Ethers keccak256):

ethers.utils.keccak256(ethers.utils.toUtf8Bytes("ADMIN"));

Will be the same hash as the one stored in the contract. But it won't really help you with anything.

It sounds like you're trying to make sure that there is an admin with permissions to mint or something of the like. This is not generally handled by a frontend, but rather in the actual contract. I don't know what library you're using, but there should be a function to add a role to an address. (Here is where it is in the OZ Access Control.) Oftentimes there's a default role the deployer receives.

Functions you would like to protect should have a require or custom error. For example:

// this isn't exactly like the OZ Access Control listed above
mapping(bytes32 => mapping(address => bool)) roles;

function mint(address recipient, uint256 quantity) public { require(roles[ADMIN][msg.sender], "unauthorized"); // the rest of the mint logic goes here

The Renaissance
  • 2,749
  • 1
  • 17
  • 45