eth-erc20

ERC20 interface and example giftable token contract
Info | Log | Files | Refs | LICENSE

StaticToken.sol (2231B)


      1 pragma solidity >=0.8.0;
      2 
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 
      5 contract StaticToken {
      6 
      7 	address owner;
      8 	mapping(address => bool) minters;
      9 
     10 	// Implements ERC20
     11 	string public name;
     12 	// Implements ERC20
     13 	string public symbol;
     14 	// Implements ERC20
     15 	uint8 public decimals;
     16 	// Implements ERC20
     17 	uint256 public totalSupply;
     18 	// Implements ERC20
     19 	mapping (address => uint256) public balanceOf;
     20 	// Implements ERC20
     21 	mapping (address => mapping (address => uint256)) public allowance;
     22 
     23 	// Implements ERC20
     24 	event Transfer(address indexed _from, address indexed _to, uint256 _value);
     25 	// Implements ERC20
     26 	event TransferFrom(address indexed _from, address indexed _to, address indexed _spender, uint256 _value);
     27 	// Implements ERC20
     28 	event Approval(address indexed _owner, address indexed _spender, uint256 _value);
     29 
     30 	constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _supply) {
     31 		owner = msg.sender;
     32 		name = _name;
     33 		symbol = _symbol;
     34 		decimals = _decimals;
     35 		totalSupply = _supply;
     36 		balanceOf[owner] = _supply;
     37 	}
     38 
     39 	// Implements ERC20
     40 	function transfer(address _to, uint256 _value) public returns (bool) {
     41 		require(balanceOf[msg.sender] >= _value);
     42 		balanceOf[msg.sender] -= _value; 
     43 		balanceOf[_to] += _value;
     44 		emit Transfer(msg.sender, _to, _value);
     45 		return true;
     46 	}
     47 
     48 	// Implements ERC20
     49 	function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
     50 		require(allowance[_from][msg.sender] >= _value);
     51 		require(balanceOf[_from] >= _value);
     52 		allowance[_from][msg.sender] = allowance[_from][msg.sender] - _value;
     53 		balanceOf[_from] -= _value; 
     54 		balanceOf[_to] += _value;
     55 		emit TransferFrom(_from, _to, msg.sender, _value);
     56 		return true;
     57 	}
     58 
     59 	// Implements ERC20
     60 	function approve(address _spender, uint256 _value) public returns (bool) {
     61 		if (_value > 0) {
     62 			require(allowance[msg.sender][_spender] == 0);
     63 		}
     64 		allowance[msg.sender][_spender] = _value;
     65 		emit Approval(msg.sender, _spender, _value);
     66 		return true;
     67 	}
     68 
     69 	// Implements EIP165
     70 	function supportsInterface(bytes4 _sum) public pure returns (bool) {
     71 		if (_sum == 0xb61bc941) { // ERC20
     72 			return true;
     73 		}
     74 		if (_sum == 0x01ffc9a7) { // EIP165
     75 			return true;
     76 		}
     77 		return false;
     78 	}
     79 }