Hi Guys, I want to sell tokens and get other ERC20 token instead. I have put this function that works with the commented code but not with the transferFrom function. Does anyone can help me here?
function buyToken(uint _amountBUSD) public icoActive {
require(whitelisted[msg.sender], "user not whitelisted");
uint tokenAmount = ((((_amountBUSD*10**18)/3)*100));
require(tokenAmount > 0, "Token amount 0");
require((tokenAmount >= 1666000000000000000000) && (66666666666666666666667 >= tokenAmount), "Not between 50 or 2000 Busd");
// int facuTokenPriceBNB = facuTokenPriceInBNB();
// require(int(msg.value) >= facuTokenPriceBNB * int(_amount), "");
require(token.balanceOf(address(this)) >= tokenAmount, "More than available on contract");
require(boughtTokens[msg.sender] == false || sales[msg.sender].amount + tokenAmount <= 66666666666666666666667, "You only can buy 2000 Busd");
// ethFunds.transfer(msg.value);
ERC.transferFrom(msg.sender, ethFunds, (_amountBUSD*10**18));
tokensSold += tokenAmount;
sales[msg.sender] = Sale(msg.sender, tokenAmount, false);
transaction[transactionCount] = Sale(msg.sender, tokenAmount, false);
transactionCount++;
boughtTokens[msg.sender] = true;
emit Sell(msg.sender, (_amountBUSD*10**18));
}