ERC20 - sendTokenToFee(contractTokenBalance) not working

Hi,

Recently we summited one ticket with question and we got right support from community. Thanks a lot for that!
Now we have one more and last issue. Hope someone could help with that.

You could check full contract code here: https://pastebin.com/kGM3FuZH

Currently, when someone buy or sell tokens some of them redistributed to holders and some added to contract address. Right after that tokens from contract got swapped to eth and sent to 4 wallets.

Problem:

  • We need to take tokens from contract and send to 4 wallets in TOKENS NOT ETH when someone buys the tokens.

This part is swapping the tokens came to the contract during sell:

uint256 contractTokenBalance = balanceOf(address(this));
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if (contractETHBalance > 0) {
        sendETHToFee(address(this).balance);
}

...

    function sendETHToFee(uint256 amount) private {
        _charityFirst.transfer(amount.mul(40).div(100));
        _charitySecond.transfer(amount.mul(40).div(100));
        _marketing.transfer(amount.mul(20).div(100));
    }

So we added the code to the part where someone buys:

                uint256 contractTokenBalance = balanceOf(address(this));
                if (contractTokenBalance > 0) {
                    sendTokenToFee(contractTokenBalance);
                }

...

    function sendTokenToFee(uint256 amount) private {
        _charityFirst.transfer(amount.mul(40).div(100));
        _charitySecond.transfer(amount.mul(40).div(100));
        _burnWallet.transfer(amount.mul(20).div(100));
    }

But it does not work when the contract balance > 0 and just giving an error in UNISWAP when you trying to swap ETH for Token second time (that time contract token balance > 0).

Uniswap error:

The output token cannot be transferred. There may be an issue with the output token.

I just thinking maybe the problem is related to the big numbers goin thru these variables?

We are using Ropsten test network for now.

Thank you in advance!

UPDATE:
Tested separately this function and transaction fails. There are no logs unfortunately..

    function sendTokenToFeeManual() public onlyOwner {
        uint256 contractTokenBalance = balanceOf(address(this));
        if (contractTokenBalance > 0) {
            sendTokenToFee(contractTokenBalance);
        }
    }

Solved by changes made below, but don’t like because it goes as a standard transaction (not a call/internal transaction):

    function sendTokenToFeeOnBuy(uint256 amount) private {
        /*_charityFirst.transfer(amount.mul(40).div(100));
        _charitySecond.transfer(amount.mul(40).div(100));
        _burnWallet.transfer(amount.mul(20).div(100));*/
        uint256 charityFirstAmt = amount.mul(40).div(100);
        uint256 charitySecondAmt = amount.mul(40).div(100);
        uint256 charityBurnAmt = amount.mul(20).div(100);
        _tokenTransfer(address(this), _charityFirst, charityFirstAmt, false);
        _tokenTransfer(address(this), _charitySecond, charitySecondAmt, false);
        _tokenTransfer(address(this), _burnWallet, charityBurnAmt, false);
    }

Do you know how to use these transactions in the call/internal transaction?

What do you mean by this?

1 Like

In this case it's going as internal transaction and on etherscan only single transaction displayed and fees are hidden insight the internal transaction tab:

    function sendETHToFee(uint256 amount) private {
        _charityFirst.transfer(amount.mul(40).div(100));
        _charitySecond.transfer(amount.mul(40).div(100));
        _marketing.transfer(amount.mul(20).div(100));
    }

In my case it generates 4 transactions. 1 buyer and 3 fees transactions displayed:
image

I don’t really understand why it would be showing as external transactions. Please include full screenshots.