0

code:

 function collect(address addr)  public returns (uint256){
        Deposit[] storage invests = users[addr].deposits;
         uint256  i = 0;
         uint256 profit = 0;
        while (i < invests.length){
            Deposit storage  invest = invests[i];
            if (invest.lastDepositTime < invest.depositTime.add(200 days)){
                 uint256  remainedTime = BOX_PERIOD[0].sub(invest.lastDepositTime.sub(invest.depositTime));
              //  timeSpent = now.sub(invest.lastDepositTime);

                 
          
 
                 
                if (remainedTime > 0){
                    
                   uint256 a;               
                   uint256 b;
                   uint256 c;
                   uint256 d;
                   uint256 e;
                   uint256 f;
                   uint256 g;
                   uint256 timespend;
                   uint256 i2; 
                   uint256 j; 
                   uint256 k;   
                   uint256 h;   
                 
                  a=profit;
                  b=24;
                  c=100;
                  d=60;
                  e=100;
                  f=60;
                  g=100;
                  
                  h=10000000;
                  timespend=now.sub(invest.lastDepositTime);

                profit = a.div(b).mul(c).div(d).mul(e).div(f).mul(g).div(h);

I got error: browser/test1.sol:76:30: CompilerError: Stack too deep, try removing local variables. profit = invest.amount.div(24).mul(100).div(60).mul(100).div(60).mul(100).div(1000000).mul(timeSpent); ^----^

This is only if add .mul(timeSpent),other way works.

I have tried too uint[8], uint[256] I got data location bust be storage or memory for variable but still not works..

4
  • 4
    Does this answer your question? How to Fix "Stack Too Deep" Error? (you may also take a look at soliditydeveloper.com/stacktoodeep) Oct 6, 2020 at 5:41
  • hi i have tried but still i get errors with different way. check above my new code but also i have tried with another example and is the same. I hope you can help me.
    – progy85
    Oct 6, 2020 at 10:20
  • @progy85 Simplify the code, remove unnecessary local variables profit = invest.amount.mul(100*100*100*timeSpent).div(24*60*60*1000000); or better invest.amount.mul(timeSpent).div(24*60*60);
    – Ismael
    Oct 6, 2020 at 12:27
  • 1
    hey thanks this resolved my problem. please add answer and i will add as resolved. I can't do this in my side.
    – progy85
    Oct 6, 2020 at 15:29

0

Browse other questions tagged or ask your own question.