Stack too deep in solidity

this contract has a wallet address( charity) that take 3% tax on every transaction. now i want to add another wallet( dev) that will take 4% tax on every transaction. i have tried but it says stack too deep.

here is the code…

Hey @iammoud2

In your code there is a lot of global variables, most likely this was a problem when you tryed to add a new one. There is a limit of 16 or 18 variables.

So, how to beat this limit?

You can use functions _getValue instead of creating global variables. And it’s already used in the provided code:

For example:

Instead of creating variable :

address private _devWalletAddress = 0x000000000000000000000000000000000000dEaD;   //Burn

You can add this variable to:

    function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256) {
        uint256 tFee = calculateTaxFee(tAmount);
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tCharity = calculateCharityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity).sub(tCharity);
        address private _devWalletAddress = 0x000000000000000000000000000000000000dEaD;  
        return (tTransferAmount, tFee, tLiquidity, tCharity, _devWalletAddress);
    }

thank you for your reply, i will try this and get back to you

1 Like
am i doing something wrong?

function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256) {
        uint256 tFee = calculateTaxFee(tAmount);
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tCharity = calculateCharityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity).sub(tCharity);
        address private _devWalletAddress = 0xE8A4eF706d4e57210cB6CE5781C052Cc0331B616;  
        return (tTransferAmount, tFee, tLiquidity, tCharity, _devWalletAddress);
    }Preformatted text

is said: Expected ‘;’ but got ‘private’ where am i missing/ having typo?

Oh, sorry my bad. It was just an exapmle. Use it without private

address _devWalletAddress = 0xE8A4eF706d4e57210cB6CE5781C052Cc0331B616;  

i dont know how it may sound, but can you plz complete the code?

What do you mean?
To add the function of receiving the address or the whole smart contract?

To add the function of receiving the address.

so, i need to set the 4% tax exact same way as tha charity wallet is added?

I just want to clarify. Does the code from the github compile without problems?

yes it does…but i want to add another wallet(dev) as mentioned

The problem is I can’t deploy it to the local testnet because of routers in the smartcontract… and test it. So, I need your help.

Try to add _devAddress

address private _charityWalletAddress = 0x000000000000000000000000000000000000dEaD;   //Burn
address private _devAddress = 0x000000000000000000000000000000000000dEaD;   //Burn

And the question: which function you tryied to change for making extra fee?

let me change the router address for testnet

1 Like

I can use 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 bsc testnet of pancakeswap router i guess

1 Like

you can also change the owner address on line 494( if you want)

I need to leave now. As soon as I return I will answer you.

ok…tnx for the help

Hey @iammoud2

Could you share the code which has “too deep” error.
Because the code is too comlicated to rewrite it by myself :man_mechanic:

i have change the code in github …now it has " stack too deep error"

Hey @iammoud2

Check your github