AccessControlERC20MintBase.sol 830 B

12345678910111213141516171819202122232425
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {AccessControl} from "../../../access/AccessControl.sol";
  4. import {ERC20} from "../../../token/ERC20/ERC20.sol";
  5. contract AccessControlERC20MintBase is ERC20, AccessControl {
  6. // Create a new role identifier for the minter role
  7. bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
  8. error CallerNotMinter(address caller);
  9. constructor(address minter) ERC20("MyToken", "TKN") {
  10. // Grant the minter role to a specified account
  11. _grantRole(MINTER_ROLE, minter);
  12. }
  13. function mint(address to, uint256 amount) public {
  14. // Check that the calling account has the minter role
  15. if (!hasRole(MINTER_ROLE, msg.sender)) {
  16. revert CallerNotMinter(msg.sender);
  17. }
  18. _mint(to, amount);
  19. }
  20. }