How do I add permissions to each role in AccessControl?

Now in access contorl.sol,there are some basic operations ,like grantRole(),revokeRole(), but you need assign permissions to each role to achieve access control purposes…Later, permission inheritance can also be added .
But I have no idea about adding permissions.
Can anyone give me some ideas?
Thank you!
:computer: Environment

:memo:Details

:1234: Code to reproduce

1 Like

Hi @wangyuyue,

We can use AccessControl to define roles and then check for those roles when accessing certain functions.

The example below (from the documentation) shows a Minter Role and a Burner Role, with the Minter Role having permission to mint (call the mint function) and the Burner Role having permission to burn (call the burn function)

from: https://docs.openzeppelin.com/contracts/3.x/access-control#using-access-control

// contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20, AccessControl {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

    constructor(address minter, address burner) public ERC20("MyToken", "TKN") {
        _setupRole(MINTER_ROLE, minter);
        _setupRole(BURNER_ROLE, burner);
    }

    function mint(address to, uint256 amount) public {
        require(hasRole(MINTER_ROLE, msg.sender), "Caller is not a minter");
        _mint(to, amount);
    }

    function burn(address from, uint256 amount) public {
        require(hasRole(BURNER_ROLE, msg.sender), "Caller is not a burner");
        _burn(from, amount);
    }
}

Is this what you meant?

Hi @wangyuyue,

I just wanted to check if you had your question answered?

2 posts were split to a new topic: How to check roles in access control?