0

I keep getting the 'stack too deep' error on solidity. I was wondering if anyone can help me fix this with in following code:


function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
        uint256 tFee = calculateTaxFee(tAmount);
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tDev = calculateDevFee(tAmount);
        uint256 tBurn = calculateBurnFee(tAmount);
        uint256 tCharity = calculateCharityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
                tTransferAmount = tTransferAmount.sub(tDev);
                tTransferAmount = tTransferAmount.sub(tCharity);
                tTransferAmount = tTransferAmount.sub(tBurn);

        return (tTransferAmount, tFee, tLiquidity, tDev, tBurn, tCharity);
    }

Thanks!

2
  • Unfortunately not, I've already read that. I attempted putting the code into two seperate functions, but now I get an error expected '(' but for identified function. Commented Jun 8, 2021 at 8:07
  • @GandalfTheGrey Try some of the other solutions mentioned in that question, using less variables, using an array or struct to keep the variables, don't return that many variables, return an array or struct instead.
    – Ismael
    Commented Jun 9, 2021 at 1:46

1 Answer 1

1

I think, it would be better if you define a structure and then return as a memory pointer to the result.

structure MyReturnData {
   uint256 tTransferAmount;
   uint256 tFee;
   uint256 tLiquidity;
   uint256 tDev;
   uint256 tBurn;
   uint256 tCharity;
}

function _getTValues(uint256 tAmount) private view returns (MyReturnData memory) {}

Sometime, if you put your code inside the magic {} it would work.

1
  • Thank you! Unfortunately, I now get the error ParserError: Expected ';' but got '{' structure myReturnData. Any ideas? Commented Jun 8, 2021 at 11:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.