I'm creating a simple ICO contract, it sends the amount of the token bought to the buyer as soon as the contract receives ether, and then sends the received ether to a different wallet, I've been testing it on remix all day but the contracts receive the ether but doesn't send out the ether to the wallet neither does the buyer received hers. Here's the buying function.
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);
uint256 tokens = _getTokenAmount(weiAmount);
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount)
}
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount.mul(rate);
}
function _processPurchase(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
_deliverTokens(_beneficiary, _tokenAmount);
}
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
token.transfer(_beneficiary, _tokenAmount);
}
function _forwardFunds() internal {
bool sent = wallet.transfer(address(wallet),msg.value);
require(sent, "Transaction failed");
}