Skip to content

Instantly share code, notes, and snippets.

@lukecurtis93
Last active March 21, 2022 14:34
Show Gist options
  • Save lukecurtis93/faca57d1876fdc7866f9800504fbd05d to your computer and use it in GitHub Desktop.
Save lukecurtis93/faca57d1876fdc7866f9800504fbd05d to your computer and use it in GitHub Desktop.
An upgradeable token.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract MyToken is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, AccessControlUpgradeable, OwnableUpgradeable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
function initialize() public initializer {
__ERC20_init("MyToken", "TOK");
__Ownable_init();
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
_mint(msg.sender, 100000 * 10 ** decimals());
}
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(to, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment