How to fix this issue

function _transfer(
address from,
address to,
uint256 amount
) internal override {
require(from != address(0), “ERC20: transfer from the zero address”);
require(to != address(0), “ERC20: transfer to the zero address”);
require(!_isBlacklisted[to], “Recipient is backlisted”);
require(!_isBlacklisted[from], “Sender is backlisted”);
uint256 RewardsFee;
uint256 deadFees;
uint256 marketingFees;
uint256 liquidityFee;
uint256 devFees;
uint256 CharityFees;

    checkTxLimit(from, amount);

    if (!canTransferBeforeTradingIsEnabled[from]) {
        require(tradingEnabled, "Trading has not yet been enabled");
    }
    if (amount == 0) {
        super._transfer(from, to, 0);
        return;
    } else if (
        !swapping && !_isExcludedFromFees[from] && !_isExcludedFromFees[to]
    ) {
        bool isSelling = automatedMarketMakerPairs[to];
        bool isBuying = automatedMarketMakerPairs[from];

        if (!isBuying && !isSelling) {
            uint256 tFees = amount.mul(transferFee).div(100);
            amount = amount.sub(tFees);
            super._transfer(from, address(this), tFees);
            super._transfer(from, to, amount);
            dividendTracker.setBalance(from, getStakingBalance(from));
            dividendTracker.setBalance(to, getStakingBalance(to));
            return;
        }
        
        else if (!isBuying && stakingEnabled) {
            require(
                stakingUntilDate[from] <= block.timestamp,
                "Tokens are staked and locked!"
            );
            if (stakingUntilDate[from] != 0) {
                stakingUntilDate[from] = 0;
                stakingBonus[from] = 0;
            }
        }

        else if (isSelling) {
            RewardsFee = sellRewardsFee;
            deadFees = sellDeadFees;
            marketingFees = sellMarketingFees;
            liquidityFee = sellLiquidityFee;
            devFees = sellDevFee;
            CharityFees = sellCharityFees;

            if (AntiBot) {
            require(block.timestamp >= _holderLastTransferTimestamp[tx.origin] + cooldowntimer,
                    "cooldown period active, come back in 24hours");
            _holderLastTransferTimestamp[tx.origin] = block.timestamp;

            }

        } else if (isBuying) {
            RewardsFee = buyRewardsFee;
            deadFees = buyDeadFees;
            marketingFees = buyMarketingFees;
            liquidityFee = buyLiquidityFee;
            devFees = buyDevFee;
            CharityFees = buyCharityFee;

            if (AntiBot) {
            require(block.number > launchblock + 2,"you shall not pass");
            require(tx.gasprice <= gasPriceLimit,"Gas price exceeds limit.");
            require(_holderLastTransferBlock[tx.origin] != block.number,"Too many TX in block");
            _holderLastTransferBlock[tx.origin] = block.number;
        }
        
        uint256 contractBalanceRecipient = balanceOf(to);
        require(contractBalanceRecipient + amount <= maxWallet,
                "Exceeds maximum wallet token amount." );
        require(amount <= maxTransactionAmount,
                "Exceeds maximum TX transaction amount");
        }

        uint256 totalFees = RewardsFee
            .add(liquidityFee + marketingFees + devFees + CharityFees);

        uint256 contractTokenBalance = balanceOf(address(this));

        bool canSwap = contractTokenBalance >= swapTokensAtAmount;

        if (canSwap && !automatedMarketMakerPairs[from]) {
            swapping = true;

            if (swapAndLiquifyEnabled && liquidityFee > 0 && totalBuyFees > 0) {
                uint256 totalBuySell = buyAmount.add(sellAmount);
                uint256 swapAmountBought = contractTokenBalance
                    .mul(buyAmount)
                    .div(totalBuySell);
                uint256 swapAmountSold = contractTokenBalance
                    .mul(sellAmount)
                    .div(totalBuySell);

                uint256 swapBuyTokens = swapAmountBought
                    .mul(liquidityFee)
                    .div(totalBuyFees);

                uint256 swapSellTokens = swapAmountSold
                    .mul(liquidityFee)
                    .div(totalSellFees);

                uint256 swapTokens = swapSellTokens.add(swapBuyTokens);

                swapAndLiquify(swapTokens);
            }

            uint256 remainingBalance = balanceOf(address(this));
            swapAndSendDividends(remainingBalance);
            buyAmount = 0;
            sellAmount = 0;
            swapping = false;
        }

        uint256 fees = amount.mul(totalFees).div(100);
        uint256 burntokens;

        if (deadFees > 0) {
        burntokens = amount.mul(deadFees) / 100;
        super._transfer(from, DEAD, burntokens);
        _totalSupply = _totalSupply.sub(burntokens);

        }

        amount = amount.sub(fees + burntokens);

        if (isSelling) {
            sellAmount = sellAmount.add(fees);
        } else {
            buyAmount = buyAmount.add(fees);
        }

        super._transfer(from, address(this), fees);

        uint256 gas = gasForProcessing;

        try dividendTracker.process(gas) returns (
            uint256 iterations,
            uint256 claims,
            uint256 lastProcessedIndex
        ) {
            emit ProcessedDividendTracker(
                iterations,
                claims,
                lastProcessedIndex,
                true,
                gas,
                tx.origin
            );
        } catch {}
    }

    super._transfer(from, to, amount);
    dividendTracker.setBalance(from, getStakingBalance(from));
    dividendTracker.setBalance(to, getStakingBalance(to));
}

I got error on this line

What is the error from that?

It says compiler error, stack too deep

What is the difference between that div(100) and that / 100 syntax?

what version of solidity are you using?

you could try using structs and arrays to reduce the stack, i personally seen this error when trying to input too many function parameters.

have you tried doing what the compiler suggested?

I am using this version of solidity Version 0.8.17

why are you using safe math?

I thought it’s necessary to use it ? Or is it not?

I haven’t tried using struct

no, you dont need it in solidity 8+

it has it built in, so you double safe mathing, if that makes sense

I am still learning solidity on my free time. Any help to fix that?

Oh okay, that’s a great one then, I am still learning

I really need a tutor :joy: don’t know if you are chance to do that for me

you can try removing the unnecessary stuff, cleaning it up, and reducing the stack.

and/or

try what the compiler suggest

unless anyone else has any more suggestions

1 Like

I’m really active on the discord smart contract help section.

My screen is kinda broken on my laptop and is flickering atm,

I still try to help out when i can

1 Like

you dont need this section in the beginning of the function,

uint256 RewardsFee;
uint256 deadFees;
uint256 marketingFees;
uint256 liquidityFee;
uint256 devFees;
uint256 CharityFees;

you can declare the type when you give the variable a value.

1 Like

Thanks for the great review I love that

try not to save unnecessary variables in the stack, or unnecessary variables in general,

reuse what you can

like this:

 RewardsFee = sellRewardsFee;
            deadFees = sellDeadFees;
            marketingFees = sellMarketingFees;
            liquidityFee = sellLiquidityFee;
            devFees = sellDevFee;
            CharityFees = sellCharityFees;

whats the point of resaving these global variables locally?

1 Like