Last active
September 25, 2019 11:39
-
-
Save MajdT51/97a982fa294329079b69db6e69cca79b to your computer and use it in GitHub Desktop.
example contract using AddrArrayLib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >= 0.4.25 < 0.6.0; | |
import '../node_modules/openzeppelin solidity/contracts/ownership/Ownable.sol'; | |
import '../node_modules/openzeppelin-solidity/contracts/math/SafeMath.sol'; | |
import './AddrArrayLib.sol'; | |
contract TokenContract is Ownable { | |
using AddrArrayLib for AddrArrayLib.Addresses; | |
using SafeMath for uint256; | |
// List of trusted addresses which can mint tokens | |
AddrArrayLib.Addresses trustedMinters; | |
uint256 public totalSupply; | |
mapping (address => uint256) balances; | |
constructor () public { | |
totalSupply = 100; | |
balances[msg.sender] = 100; | |
} | |
function addMinter(address minter) public onlyOwner() { | |
trustedMinters.pushAddress(minter); | |
} | |
function removeMinter(address minter) public onlyOwner() { | |
trustedMinters.removeAddress(minter); | |
} | |
function mintToken(address to, uint256 amount) external { | |
require(trustedMinters.exists(msg.sender), 'The sender address is not registered as a Minter'); | |
totalSupply = totalSupply.add(amount); | |
balances[to] = balances[to]. add(amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment