Skip to content

Instantly share code, notes, and snippets.

@torralbaalla
Created September 13, 2019 16:25
Show Gist options
  • Save torralbaalla/0a4a604d17729fcccbf5fe4faa7df2c6 to your computer and use it in GitHub Desktop.
Save torralbaalla/0a4a604d17729fcccbf5fe4faa7df2c6 to your computer and use it in GitHub Desktop.
YetAnotherToken Ethereum contract.
/*
* yet.sol
*
* Copyright 2019 Alvarito050506 <donfrutosgomez@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
pragma solidity >= 0.5.11;
library SafeMath
{
function add(uint a, uint b) internal pure returns (uint c)
{
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c)
{
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c)
{
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c)
{
require(b > 0);
c = a / b;
}
}
interface IERC20
{
function balanceOf(address _owner) external view returns (uint256);
function totalSupply() external view returns (uint256);
function transfer(address _to, uint256 _value) external returns (bool success);
function approve(address _spender, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
event Transfer(address _from, address _to, uint256 _value);
event Approval(address _owner, address _spender, uint256 _value);
}
contract YetAnotherToken is IERC20
{
using SafeMath for uint;
string public name;
string public symbol;
string public version;
uint8 public decimals;
uint256 private _totalSupply;
uint256 private _initialSupply;
address private owner;
mapping (address => uint256) private balances;
mapping(address => mapping (address => uint256)) private allowed;
constructor() public
{
name = "YetAnotherToken";
symbol = "YET";
version = "v0.1.0";
decimals = 2;
_totalSupply = 160000000;
_initialSupply = _totalSupply;
owner = msg.sender;
balances[owner] = _initialSupply;
}
function balanceOf(address _owner) public view returns (uint256)
{
return balances[_owner];
}
function totalSupply() public view returns (uint256)
{
return _totalSupply.sub(balances[address(0x00)]);
}
function transfer(address _to, uint256 _value) public returns (bool success)
{
require(balances[msg.sender] >= _value);
require(balances[_to] + _value >= balances[_to]);
balances[msg.sender].sub(_value);
balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool success)
{
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
{
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from].sub(_value);
balances[_to].add(_value);
allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
event Transfer(address _from, address _to, uint256 _value);
event Approval(address _owner, address _spender, uint256 _value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment