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!

  • 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. – GandalfTheGrey Jun 08 '21 at 08: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 Jun 09 '21 at 01:46

1 Answers1

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.