# Can't send ETH to ERC20 contract [closed]

I have ERC20 contract

``````pragma solidity ^0.5.7;

library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}

uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");

return c;
}

/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold

return c;
}

/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;

return c;
}

/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");

return c;
}

/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
}

contract ERC20 {

using SafeMath for uint256;

mapping (address => uint256) public balances;

mapping (address => mapping (address => uint)) public allowed;

//Fix for short address attack against ERC20
modifier onlyPayloadSize(uint size) {
assert(msg.data.length == size + 4);
_;
}

function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}

function transfer(address _recipient, uint256 _value) public onlyPayloadSize(2*32){
require(balances[msg.sender] >= _value && _value > 0);
balances[msg.sender].sub(_value);
emit Transfer(msg.sender, _recipient, _value);
}

function transferFrom(address _from, address _to, uint256 _value) public {
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0);
balances[_from].sub(_value);
allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
}

function  approve(address _spender, uint _value) public {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
}

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

//Event which is triggered to log all transfers to this contract's event log
event Transfer(
uint _value
);

//Event which is triggered whenever an owner approves a new allowance for a spender.
event Approval(
uint _value
);
}

contract yMTCZ is ERC20 {

string public constant name = "MyCoinZy";

string public constant symbol = "yMTCZ";

uint8 public constant decimals = 6;

uint256 public totalSupply = 1000000 * 10**6;

uint256 public constant unitsOneEthCanBuy = 200;     // How many units of your coin can be bought by 1 ETH

uint256 public totalEthInWei;

address payable public fundsWallet = msg.sender;

string public  version = "1.0";

constructor() yMTCZ() public {

balances[msg.sender] = totalSupply;

}

function () external payable {
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
require(balances[fundsWallet] >= amount && allowed[fundsWallet][msg.sender] >= amount && amount > 0);
balances[fundsWallet].sub(amount);
allowed[fundsWallet][msg.sender].sub(amount);
emit Transfer(fundsWallet, msg.sender, amount);
fundsWallet.transfer(totalEthInWei);
}

}
``````

I can't buy token using ETH. I use payable function to accept ETH and send tokens to user wallet.

## closed as unclear what you're asking by goodvibration, Eli Drion, Shawn Tabrizi, shane, flygoingMay 8 at 16:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.