Last active
November 8, 2019 07:48
-
-
Save doey-default/9e6801cb79cc8c9cb255649b5af7231e to your computer and use it in GitHub Desktop.
This file contains hidden or 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.5.0; | |
| import "./SafeMath.sol"; | |
| interface IERC20 { | |
| function totalSupply() external view returns (uint256); | |
| function balanceOf(address account) external view returns (uint256); | |
| function transfer(address recipient, uint256 amount) external returns (bool); | |
| function allowance(address owner, address spender) external view returns (uint256); | |
| function approve(address spender, uint256 amount) external returns (bool); | |
| function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| event Approval(address indexed owner, address indexed spender, uint256 value); | |
| } | |
| contract MyToken is IERC20 { | |
| using SafeMath for uint; | |
| string public constant name = "MyToken"; | |
| string public constant symbol = "MTK"; | |
| uint8 public constant decimals = 6; | |
| uint private _totalSupply; | |
| uint private totalProvided; | |
| address payable private owner; | |
| mapping(address => uint) private balances; | |
| mapping(address => mapping(address => uint)) private allowed; | |
| constructor() public | |
| { | |
| _totalSupply = 100000 * 10 ** uint(decimals); | |
| owner = msg.sender; | |
| balances[owner] = _totalSupply; | |
| totalProvided = 0; | |
| } | |
| function totalSupply() external view returns (uint) | |
| { | |
| return _totalSupply; | |
| } | |
| function balanceOf(address _account) external view returns (uint) | |
| { | |
| return balances[_account]; | |
| } | |
| function transfer(address _recipient, uint _amount) external returns (bool) | |
| { | |
| if (_amount > 0 && balances[msg.sender] >= _amount) { | |
| balances[msg.sender] = balances[msg.sender].sub(_amount); | |
| balances[_recipient] = balances[_recipient].add(_amount); | |
| emit Transfer(msg.sender, _recipient, _amount); | |
| return true; | |
| } | |
| return false; | |
| } | |
| function allowance(address _owner, address _spender) external view returns (uint) | |
| { | |
| return allowed[_owner][_spender]; | |
| } | |
| function approve(address _spender, uint _amount) external returns (bool) | |
| { | |
| if (_amount > 0 && balances[msg.sender] >= _amount) { | |
| allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_amount); | |
| emit Approval(msg.sender, _spender, _amount); | |
| return true; | |
| } | |
| return false; | |
| } | |
| function transferFrom(address _sender, address _recipient, uint _amount) external returns (bool) | |
| { | |
| if (_amount > 0 && balances[_sender] >= _amount && allowed[_sender][msg.sender] >= _amount) { | |
| allowed[_sender][msg.sender] = allowed[_sender][msg.sender].sub(_amount); | |
| balances[_sender] = balances[_sender].sub(_amount); | |
| balances[_recipient] = balances[_recipient].add(_amount); | |
| emit Transfer(msg.sender, _recipient, _amount); | |
| return true; | |
| } | |
| return false; | |
| } | |
| function burn(uint _amount) external onlyOwner returns (bool) { | |
| if( _amount > 0 && balances[owner] >= _amount ) { | |
| balances[owner] = balances[owner].sub(_amount); | |
| _totalSupply = _totalSupply.sub(_amount); | |
| return true; | |
| } | |
| return false; | |
| } | |
| function buyToken() payable external returns (bool) { | |
| if(msg.value >= 0 && now < 1573111078 | |
| && totalProvided.add(msg.value * 10000) <= _totalSupply | |
| && msg.value * 10000 <= balances[owner]){ | |
| uint _amount = msg.value * 10000; | |
| balances[owner] = balances[owner].sub(_amount); | |
| balances[msg.sender] = balances[msg.sender].add(_amount); | |
| if(owner.send(msg.value)){ | |
| emit Transfer(owner, msg.sender, _amount); | |
| totalProvided = totalProvided.add(msg.value * 10000); | |
| return true; | |
| } else { | |
| revert(); | |
| } | |
| } | |
| return false; | |
| } | |
| modifier onlyOwner { | |
| require(owner == msg.sender); | |
| _; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment