-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyRedBullToken.sol
33 lines (25 loc) · 1.01 KB
/
MyRedBullToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
// Simple ERC20 token example utilising openzeppelin base contracts.
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
contract MyRedBullToken is ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
event RedBullPurchased(address indexed receiver, address indexed buyer);
constructor() ERC20("RedBullToken", "RBT") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
}
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(to, amount);
}
function buyOneRedBull() public {
_burn(_msgSender(), 1);
emit RedBullPurchased(_msgSender(), _msgSender());
}
function buyOneRedBullFrom(address account) public {
_spendAllowance(account, _msgSender(), 1);
_burn(account, 1);
emit RedBullPurchased(_msgSender(), account);
}
}