Skip to content

Instantly share code, notes, and snippets.

@jigar23
Created June 11, 2018 15:08
Show Gist options
  • Save jigar23/3dad21d6942e55bb262154532e26e8c3 to your computer and use it in GitHub Desktop.
Save jigar23/3dad21d6942e55bb262154532e26e8c3 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.23+commit.124ca40d.js&optimize=false&gist=
pragma solidity ^0.4.0;
interface ERC20 {
function totalSupply() constant returns (uint _totalSupply);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns (bool success);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint remaining);
}
pragma solidity ^0.4.0;
import "browser/ERC20.sol";
contract MyFirstToken is ERC20 {
string public constant symbol = "MFT";
string public constant name = "My First Token";
uint8 public constant decimals = 18;
uint private constant __totalSupply = 1000;
mapping (address => uint) private __balanceOf;
mapping (address => mapping(address => uint)) private __allowances;
constructor() public
{
__balanceOf[msg.sender] = __totalSupply;
}
function totalSupply() constant returns (uint _totalSupply)
{
_totalSupply = __totalSupply;
}
function balanceOf(address _owner) constant returns (uint balance)
{
balance = __balanceOf[_owner];
}
function transfer(address _to, uint _value) returns (bool success)
{
if (_value > 0 && __balanceOf[msg.sender] >= _value) {
__balanceOf[msg.sender] -= _value;
__balanceOf[_to] += _value;
return true;
}
return false;
}
function transferFrom(address _from, address _to, uint _value) returns (bool success)
{
if (_value > 0 && __allowances[_from][msg.sender] >= _value
&& __balanceOf[_from] >= _value) {
__balanceOf[_from] -= _value;
__balanceOf[_to] += _value;
__allowances[_from][msg.sender] -= _value;
return true;
}
return false;
}
function approve(address _spender, uint _value) returns (bool success)
{
if (_value > 0 && __balanceOf[msg.sender] >= _value) {
__allowances[msg.sender][_spender] = _value;
return true;
}
return false;
}
function allowance(address _owner, address _spender) constant returns (uint remaining)
{
return __allowances[_owner][_spender];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment