Hello i have this solidity code in the contract of a token, to receive ETH, send token to sender at an exchange rate and transfer ETH to owner, however on sending ETH to the contract, it fails. Please have an idea of what the issue might be
function () public payable {
fundTokens();
}
function fundTokens() public payable {
require(msg.value > 0);
uint256 tokens = msg.value.mul(exchangeRate);
require(balances[this].sub(tokens) > 0);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[this] = balances[this].sub(tokens);
Transfer(msg.sender, owner, msg.value);
forwardFunds();
}
function forwardFunds() internal {
owner.transfer(msg.value);
}
fundTokens
but the first one, try transactions. When it works - uncomment one more line and iterate.