0

I am trying to compile the following smart contract:

pragma solidity ^0.5.1; 
contract Governmental{
   uint constant TWELVE_HOURS = 12;
   
   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;
       
      // 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 ;
      }
   }
}

I am getting the error:

prg17.sol:20:10: Error: Member "send" not found or not visible after argument-dependent lookup in uint256. creditorAddresses[creditorAddresses.length - 1].send ( profitFromCrash ); ^--------------------------------------------------^

Somebody please guide me.

Zulfi.

1 Answer 1

1

creditorAddresses is declared as a uint array.

uint[] memory creditorAddresses;

Prabably you meant to declare it as an address array

address payable[] memory creditorAddresses;

Also this code creditorAddresses[creditorAddresses.length - 1] won't work when the array is empty. Which is the case if the memory array isn't initialized like the snippet.

4
  • Hi, my friend @Ismael your solution gives the arror: Error: "send" and "transfer" are only available for objects of type "address payable", not "address"., when I am using payable, I get the error: Error: Expected ';' but got 'payable', Somebody please guide me. Zulfi.
    – zak100
    Feb 19, 2021 at 16:09
  • 1
    @zak100 Sorry, my mistake. It should have been address payable[] memory creditorAddresses.
    – Ismael
    Feb 19, 2021 at 18:44
  • Hi, my firend @Ismael, I am now getting 2 errors: (1) Error: Type address[] memory is not implicitly convertible to expected type address payable[] memory. creditorAddresses = new address [](0); and (2)Error: Type uint256[] memory is not implicitly convertible to expected type uint256. creditorAmounts = new uint [](0);........Please guide me. Zulfi.
    – zak100
    Feb 21, 2021 at 5:26
  • 1
    @zak100 You can fix by allocating address payable instead. Something like creditorAddresses = new address payable[](0)
    – Ismael
    Feb 21, 2021 at 15:44

Your Answer

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

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