Skip to content

Latest commit

 

History

History
366 lines (314 loc) · 9.87 KB

PoorMansERC20.md

File metadata and controls

366 lines (314 loc) · 9.87 KB

PoorMansERC20.sol

View Source: contracts/fakes/PoorMansERC20.sol

PoorMansERC20

Contract Members

Constants & Variables

string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping(address => uint256) public balances;
mapping(address => mapping(address => uint256)) public allowed;

Events

event Transfer(address indexed _from, address indexed _to, uint256  _value);
event Approval(address indexed _owner, address indexed _spender, uint256  _value);

Functions

function (string _name, string _symbol, uint256 _supply) public nonpayable

Arguments

Name Type Description
_name string
_symbol string
_supply uint256
Source Code
constructor(
    string memory _name,
    string memory _symbol,
    uint256 _supply
  ) {
    name = _name;
    _symbol = symbol;
    decimals = 18;

    balances[msg.sender] = _supply;
    totalSupply = _supply;

    emit Transfer(address(0), msg.sender, _supply);
  }

transfer

function transfer(address _to, uint256 _value) external nonpayable
returns(bool)

Arguments

Name Type Description
_to address
_value uint256
Source Code
function transfer(address _to, uint256 _value) external returns (bool) {
    if (balances[msg.sender] >= _value && _value > 0) {
      balances[msg.sender] -= _value;
      balances[_to] += _value;
      emit Transfer(msg.sender, _to, _value);
    }

    return false;
  }

transferFrom

function transferFrom(address _from, address _to, uint256 _value) external nonpayable
returns(bool)

Arguments

Name Type Description
_from address
_to address
_value uint256
Source Code
function transferFrom(
    address _from,
    address _to,
    uint256 _value
  ) external returns (bool) {
    if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
      balances[_to] += _value;
      balances[_from] -= _value;
      allowed[_from][msg.sender] -= _value;
      emit Transfer(_from, _to, _value);
    }

    return false;
  }

balanceOf

function balanceOf(address _owner) external view
returns(balance uint256)

Arguments

Name Type Description
_owner address
Source Code
function balanceOf(address _owner) external view returns (uint256 balance) {
    return balances[_owner];
  }

approve

function approve(address _spender, uint256 _value) external nonpayable
returns(bool)

Arguments

Name Type Description
_spender address
_value uint256
Source Code
function approve(address _spender, uint256 _value) external returns (bool) {
    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);

    return false;
  }

allowance

function allowance(address _owner, address _spender) external view
returns(remaining uint256)

Arguments

Name Type Description
_owner address
_spender address
Source Code
function allowance(address _owner, address _spender) external view returns (uint256 remaining) {
    return allowed[_owner][_spender];
  }

Contracts