contract ERC20 is Context, IERC20 {
    
     using SafeMath for uint256;
    uint256 public totalSupply;
    
    // address where funds are collected
    address payable wallet = msg.sender;

    // how many token units a buyer gets per wei
    uint256 rate = 100;
    uint256 public tokens;

    // amount of raised money in wei
    uint256 public weiRaised;

    mapping(address => uint256) balances;
    mapping (address => mapping (address => uint256)) internal allowed;
    
    
    /**
     * event for token purchase logging
     * @param purchaser who paid for the tokens
     * @param beneficiary who got the tokens
     * @param value weis paid for purchase
     * @param amount amount of tokens purchased
     */
    event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
    
    function balanceOf(address _owner) public override view returns (uint256 balance) {
    return balances[_owner];
  }

  function transfer(address _to, uint256 _value) public override returns (bool) {
    require(_to != address(0));
    require(_value <= balances[msg.sender]);

    // SafeMath.sub will throw if there is not enough balance.
    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    emit 
    Transfer(msg.sender, _to, _value);
    return true;
  }

 function transferFrom(address _from, address _to, uint256 _value) public override returns (bool) {
    require(_to != address(0));
    require(_value <= balances[_from]);
    require(_value <= allowed[_from][msg.sender]);

    balances[_from] = balances[_from].sub(_value);
    balances[_to] = balances[_to].add(_value);
    allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
    emit Transfer(_from, _to, _value);
    return true;
  }

  function approve(address _spender, uint256 _value) public override returns (bool) {
    allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);
    return true;
  }

  function allowance(address _owner, address _spender) public override view returns (uint256 remaining) {
    return allowed[_owner][_spender];
  }

  function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
    allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
    emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    return true;
  }

  function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
    uint oldValue = allowed[msg.sender][_spender];
    if (_subtractedValue > oldValue) {
      allowed[msg.sender][_spender] = 0;
    } else {
      allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
    }
    emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    return true;
  }
  
   // low level token purchase function
    function buyTokens(address beneficiary) public payable 
    {
        require(beneficiary != address(0));
        require(validPurchase());

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        tokens = weiAmount.div(getRate());
        
         
        // take funds out of our token holdings
        balances[wallet] -= tokens;
        
        // deposit those tokens into the buyer's account
        balances[beneficiary] += tokens;

        // update state
        weiRaised = weiRaised.add(weiAmount);

        emit TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

        forwardFunds();
        
     
    }

     // send ether to the fund collection wallet
     
    function forwardFunds() internal {
        wallet.transfer(msg.value);
    }

    // @return true if the transaction can buy tokens
    function validPurchase() internal view returns (bool) {
       
        bool nonZeroPurchase = msg.value != 0;
        return nonZeroPurchase;
    }

    // @return the crowdsale rate
    function getRate() public view returns (uint256) {
        return rate;
    }


    // fallback function can be used to buy tokens
    fallback() external payable {
        buyTokens(msg.sender);
    }
  
     receive() external payable
  {
      
  }
  
   
}
function validPurchase() internal view returns (bool) {
       
    bool nonZeroPurchase = msg.value != 0;
    return nonZeroPurchase;
}

// @return true if the transaction can buy tokens