How to break or split a function into two function?

Recently I got the error below in the function below as you see:
CompilerError: Stack too deep, try removing local variables.

I need to know if I should split the function into two, how should I do it?

function setFees(uint256 _liquidityFee, uint256 _buybackFee, uint256 _reflectionFee, uint256 _marketingFee, uint256 _burnFee, uint256 _destributionFee, uint256 _feeDenominator) external authorized {

        liquidityFee = _liquidityFee;

        buybackFee = _buybackFee;

        reflectionFee = _reflectionFee;

        destributionFee = _destributionFee;

        burnFee = _burnFee;

        marketingFee = _marketingFee;

        totalFee = _liquidityFee.add(_buybackFee).add(_reflectionFee).add(_destributionFee).add(_burnFee).add(_marketingFee);

        feeDenominator = _feeDenominator;

        require(totalFee < feeDenominator/4);


You can create a function for total fees, set fee denominator as a state variable... You can add the require statement in your total fees function

1 Like

Could you please check if I did it in correct way?

function totalFee (uint256 _totalFee, uint256 _feeDenominator) external {
totalFee  = _totalFee;
feeDenominator  =  _feeDenominator;

requier(totalFee < feeDenominator/4)


Is okay, it would work well.
But it would have been best to enter that fee denominator as a state variable.

1 Like

This should work. Solidity is expected to not be too complicated, as errors can be unforgiving.

1 Like