0

I getting an error while declaring a conatant variable, my code is given below:

pragma solidity ^0.5.1; 
contract Governmental{
   function lendGovernmentMoney ( address buddy ) public  returns ( bool ) {
      address owner;
      uint[] memory creditorAddresses;
      uint lastTimeOfNewCredit =0;
      uint amount = msg. value ;
      uint creditorAmounts = 0;
      uint profitFromCrash = 0;
      uint round = 0;
      uint lastCreditorPayedOut = 0;
      uint constant TWELVE_HOURS = 12; 
      // check the condition to end the game
      if ( lastTimeOfNewCredit + TWELVE_HOURS > block . timestamp ) {
         msg. sender . send ( amount );
         // Sends jacpot to the last creditor
         creditorAddresses [ creditorAddresses . length - 1] . send ( profitFromCrash );
         owner . send ( this . balance );
         // Reset contract state
         lastCreditorPayedOut = 0;
         lastTimeOfNewCredit = block . timestamp ;
         profitFromCrash = 0;
         creditorAddresses = new address [](0);
         creditorAmounts = new uint [](0);
         round += 1;
         return false ;
      }
   }
}

The error message is:

solc prg17.sol prg17.sol:12:12: Error: Expected ';' but got 'constant' uint constant TWELVE_HOURS = 12; ^------^


1 Answer 1

1

You can create variables with constant keyword only as a state variables. This cannot be done for variables which are declared inside methods.

Just move uint constant TWELVE_HOURS = 12; outside of the method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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