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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyToken { string public constant name = "Bob's Token"; string public constant symbol = "BBK"; uint8 public constant decimals = 18; uint16 private constant increase = 1000; uint256 public constant totalLimit = 27000000 * (10 ** decimals); uint256 public totalSupply = 0; address private owner; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value);
modifier checkAddress(address _addr) { require(address(_addr) != address(0), "Invalid address."); _; }
modifier checkBalanceOf(address _addr, uint256 _value) { require(balanceOf[_addr] >= _value, "Insufficient balance"); _; }
modifier checkOwner() { require(msg.sender == owner, "Not owner."); _; }
constructor() { owner = msg.sender; }
function mint(address _to) public checkOwner returns (uint256) { uint256 mintValue = increase * (10 ** decimals); require(totalLimit >= (totalSupply + mintValue), "Out of limit."); totalSupply += mintValue; balanceOf[_to] += mintValue; return balanceOf[_to]; }
function transfer(address _to, uint256 _value) public checkAddress(_to) checkBalanceOf(msg.sender, _value) returns (bool success){ balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; }
function transferFrom(address _from, address _to, uint256 _value) public checkAddress(_to) checkBalanceOf(_from, _value) returns (bool success) { require(allowance[_from][msg.sender] >= _value, "No enough approve value."); allowance[_from][msg.sender] -= _value; balanceOf[_from] -= _value; balanceOf[_to] += _value; emit Transfer(_from, _to, _value); return true; }
function approve(address _spender, uint256 _value) public returns (bool success){ allowance[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } }
|