Skip to content

Instantly share code, notes, and snippets.

@supxinfy
Created August 14, 2018 09:22
Show Gist options
  • Save supxinfy/d0ec58a789d649381587105213d6318d to your computer and use it in GitHub Desktop.
Save supxinfy/d0ec58a789d649381587105213d6318d to your computer and use it in GitHub Desktop.
Simpler ERC-20
pragma solidity ^0.4.24;
/// @title ERC-20
/// @dev Simplle version of ERC-20 interface
/// @author supxinfy
contract Ownerable
{
address public owner;
constructor() public {owner = msg.sender;}
modifier onlyOwner()
{
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {owner = newOwner;}
}
contract Coin is Ownerable
{
string public constant name = "Rumbels";
string public constant symbol = "RMB";
uint32 private constant digits = 3;
uint public TotalSupply = 0;
mapping (address => uint) balances;
mapping (address => mapping (address => uint)) allowed;
event NewUser(address indexed _);
constructor() public
{
balances[msg.sender] += 10;
NewUser(msg.sender);
}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
function mint(address _to, uint _value) public onlyOwner
{
require(TotalSupply + _value >= TotalSupply && balances[_to] + _value >= balances[_to]);
balances[_to] += _value;
TotalSupply += _value;
}
function balanceOf(address _) public view returns(uint)
{
return balances[_];
}
function transferTo(address _to, uint value) public returns(bool success)
{
require (allowed[msg.sender][_to] >= value);
require (balances[msg.sender] > value);
require (balances[_to] + value > balances[_to]);
balances[msg.sender] -= value;
balances[_to] += value;
allowed[msg.sender][_to] -= value;
Transfer(msg.sender, _to, value);
return true;
}
function transferFrom(address _from, uint value) public returns(bool success)
{
require (allowed[_from][msg.sender] >= value &&
balances[_from] >= value && balances[msg.sender] + value >= balances[_from]);
allowed[_from][msg.sender] -= value;
balances[_from] -= value;
balances[msg.sender] += value;
}
function transferFrom(address _from, address _to, uint _value) public returns (bool success)
{
if(balances[_from] >= _value &&
balances[_to] + _value >= balances[_to] &&
allowed[_from][_to] >= _value)
{
balances[_from] -= _value;
balances[_to] += _value;
Transfer(_from, _to, _value);
return true;
}
return false;
}
function allowance(address _owner, address _spender) private constant returns (uint remaining)
{
return allowed[_owner][_spender];
}
function approve(address _spender, uint _value) public returns (bool success)
{
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment