-
Notifications
You must be signed in to change notification settings - Fork 3
/
Hexch token contract.sol
128 lines (100 loc) · 4.24 KB
/
Hexch token contract.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
pragma solidity ^0.5.10;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
return c;
}
}
contract StandardBurnERC20Token {
using SafeMath for uint256;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
uint256 public totalSupply;
string public name;
uint8 public decimals;
string public symbol;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) _allowances;
constructor(string memory _tokenName, string memory _tokenSymbol, uint8 _decimalUnits, uint256 _initialAmount) public {
totalSupply = _initialAmount * 10 ** uint256(_decimalUnits);
balances[msg.sender] = totalSupply;
name = _tokenName;
decimals = _decimalUnits;
symbol = _tokenSymbol;
emit Transfer(address(0), msg.sender, totalSupply);
}
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns
(bool success) {
require(_allowances[_from][msg.sender] >= _value, "ERC20: transferFrom amount exceeds allowance");
_transfer(_from, _to, _value);
_allowances[_from][msg.sender] = _allowances[_from][msg.sender].sub(_value);
return true;
}
function _transfer(address _from, address _to, uint256 _value) internal {
require(balances[_from] >= _value, "ERC20: transfer amount exceeds balance");
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(_from, _to, _value);
}
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) public returns (bool success)
{
_allowances[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return _allowances[_owner][_spender];
}
function _burn(address _from, uint256 _value) internal {
require(balances[_from] >= _value, "ERC20: burn amount exceeds balance");
balances[_from] = balances[_from].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Transfer(_from, address(0), _value);
}
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function burnFrom(address _from, uint256 _value) public {
require(_allowances[_from][msg.sender] >= _value, "ERC20: burn amount exceeds allowance");
_burn(_from, _value);
_allowances[_from][msg.sender] = _allowances[_from][msg.sender].sub(_value);
emit Transfer(_from, address(0), _value);
}
function transferArray(address[] calldata _to, uint256[] calldata _value) external {
require(_to.length == _value.length, 'ERC20: array length is not the same');
uint256 sum = 0;
for (uint256 i = 0; i < _value.length; i++) {
sum = sum.add(_value[i]);
}
require(balances[msg.sender] >= sum);
for (uint256 k = 0; k < _to.length; k++) {
_transfer(msg.sender, _to[k], _value[k]);
}
}
}