/*
Implements EIP20 token standard: https://github.com/ethereum/EIPs/issues/20
.*/pragmasolidity ^0.5.0;import"./EIP20Interface.sol";
contractEIP20isEIP20Interface{
uint256constant MAX_UINT256 =2**256-1;
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/stringpublic name; //fancy name: eg Simon Bucksuint8public decimals; //How many decimals to show.stringpublic symbol; //An identifier: eg SBXconstructor(uint256 _initialAmount,
stringmemory _tokenName,
uint8 _decimalUnits,
stringmemory _tokenSymbol
) public{
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
totalSupply = _initialAmount; // Update total supply
name = _tokenName; // Set the name for display purposes
decimals = _decimalUnits; // Amount of decimals for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
}
functiontransfer(address _to, uint256 _value) publicreturns (bool success) {
//Default assumes totalSupply can't be over max (2^256 - 1).//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.//Replace the if with this one instead.//require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]);require(balances[msg.sender] >= _value, "Insufficient balance");
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
returntrue;
}
functiontransferFrom(address _from, address _to, uint256 _value) publicreturns (bool success) {
//same as above. Replace this line with the following if you want to protect against wrapping uints.//require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]);uint256 allowance = allowed[_from][msg.sender];
require(balances[_from] >= _value && allowance >= _value, "Insufficient balance");
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
emit Transfer(_from, _to, _value);
returntrue;
}
functionbalanceOf(address _owner) publicviewreturns (uint256 balance) {
return balances[_owner];
}
functionapprove(address _spender, uint256 _value) publicreturns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
returntrue;
}
functionallowance(address _owner, address _spender)
publicviewreturns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address=>uint256) balances;
mapping (address=>mapping (address=>uint256)) allowed;
}
Contract Source Code
File 2 of 4: EIP20Interface.sol
// Abstract contract for the full ERC 20 Token standard// https://github.com/ethereum/EIPs/issues/20pragmasolidity ^0.5.0;contractEIP20Interface{
/* This is a slight change to the ERC20 base standard.
function totalSupply() constant returns (uint256 supply);
is replaced with:
uint256 public totalSupply;
This automatically creates a getter function for the totalSupply.
This is moved to the base contract since public getter functions are not
currently recognised as an implementation of the matching abstract
function by the compiler.
*//// total amount of tokensuint256public totalSupply;
/// @param _owner The address from which the balance will be retrieved/// @return The balancefunctionbalanceOf(address _owner) publicviewreturns (uint256 balance);
/// @notice send `_value` token to `_to` from `msg.sender`/// @param _to The address of the recipient/// @param _value The amount of token to be transferred/// @return Whether the transfer was successful or notfunctiontransfer(address _to, uint256 _value) publicreturns (bool success);
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`/// @param _from The address of the sender/// @param _to The address of the recipient/// @param _value The amount of token to be transferred/// @return Whether the transfer was successful or notfunctiontransferFrom(address _from, address _to, uint256 _value) publicreturns (bool success);
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens/// @param _spender The address of the account able to transfer the tokens/// @param _value The amount of tokens to be approved for transfer/// @return Whether the approval was successful or notfunctionapprove(address _spender, uint256 _value) publicreturns (bool success);
/// @param _owner The address of the account owning tokens/// @param _spender The address of the account able to transfer the tokens/// @return Amount of remaining tokens allowed to spentfunctionallowance(address _owner, address _spender) publicviewreturns (uint256 remaining);
eventTransfer(addressindexed _from, addressindexed _to, uint256 _value);
eventApproval(addressindexed _owner, addressindexed _spender, uint256 _value);
}
Contract Source Code
File 3 of 4: Owner.sol
pragmasolidity ^0.5.0;contractOwner{
addresspublic owner;
constructor () public{
owner =msg.sender;
}
// isOwner checks whether the sender is the ownermodifierisOwner() {
require (owner ==msg.sender, "Sender is not owner");
_;
}
}