Error: Member "send" not found or not visible after argument-dependent lookup in uint256

Hi,
I am trying to compile the following contract:

    pragma solidity ^0.5.1; 
    contract Governmental{
       uint constant TWELVE_HOURS = 12;
       //address[] payable creditorAddresses;
       
       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;
          address[] memory creditorAddresses;
          // 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:

Error: Member “send” not found or not visible after argument-dependent lookup in uint256.
creditorAddresses[creditorAddresses.length - 1].send ( profitFromCrash );

I changed:

uint[ ] memory creditorAddresses;

to

address[ ] payable creditorAddresses;

but I m getting the error:

prg17.sol:16:17: Error: Expected ‘;’ but got ‘payable’
address payable creditorAddresses;

Somebody please guide me.

Zulfi.

1 Like

This is how you declare an array of payable addresses:

address payable[] memory creditorAddresses;

By the way, you have quite a few other errors here. creditorAddresses is declared twice, creditorAmounts of type uint is being assigned uint[], msg.value is being used in a non-payable function, etc.

2 Likes

Hi @cameel, thanks for your response. I have converted creditorAmounts as uint[ ] but still I am getting the error:
The modified code is:

pragma solidity ^0.5.1; 
contract Governmental{
   uint constant TWELVE_HOURS = 12;
   //address[] payable creditorAddresses;
   
   function lendGovernmentMoney ( address buddy ) public  returns ( bool ) {
      address payable owner;
      address payable[ ] memory creditorAddresses;
      uint lastTimeOfNewCredit =0;
      uint amount = msg. value ;
      uint[] memory creditorAmounts = uint[](0);//Error<<<<<<<<
      uint profitFromCrash = 0;
      uint round = 0;
      uint lastCreditorPayedOut = 0;
      //address[] payable creditorAddresses;
      // 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 (address(this).balance);
         // Reset contract state
         lastCreditorPayedOut = 0;
         lastTimeOfNewCredit = block . timestamp ;
         profitFromCrash = 0;
         creditorAddresses = new address payable [](0);
         creditorAmounts = new uint [](0);
         round += 1;
         return false ;
      }
   }
}

The error message is:

prg17.sol:14:39: Error: Explicit type conversion not allowed from “int_const 0” to “uint256[ ] memory”.
uint[ ] memory creditorAmounts = uint ;
^-------^

Somebody please guide me.

Zulfi.

1 Like

To the compiler this looks like you’re trying to convert 0 to type uint[] and that’s not possible.
To allocate memory for the array you should use the new keyword:

uint[] memory creditorAmounts = new uint[](0);
2 Likes

By the way, why are you allocating an array of size zero? You know that memory arrays are not resizable, right?

2 Likes

Hi,
@cameel , Thanks a lot for this information. Is this (i.e. memory array of size zero) a vulnerability?I am trying to compile the program given in Figure 17 of :Making the smart contract smarter.
The code is still giving the ‘payable’ error as you said, I don’t know how to correct it, I have used the payable directive in the signtaure but its still giving me the error:

pragma solidity ^0.5.1; 
contract Governmental{
   uint constant TWELVE_HOURS = 12;
   //address[] payable creditorAddresses;
   
   function lendGovernmentMoney ( address buddy ) payable   returns ( bool ) {
      address payable owner;
      address payable[ ] memory creditorAddresses;
      uint lastTimeOfNewCredit =0;
      uint amount = msg. value ;
      uint[] memory creditorAmounts = new uint[](0);
      uint profitFromCrash = 0;
      uint round = 0;
      uint lastCreditorPayedOut = 0;
      //address[] payable creditorAddresses;
      // 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 (address(this).balance);
         // Reset contract state
         lastCreditorPayedOut = 0;
         lastTimeOfNewCredit = block . timestamp ;
         profitFromCrash = 0;
         creditorAddresses = new address payable [](0);
         //creditorAmounts = new uint [](0);
         round += 1;
         return false ;
      }
   }
}

prg17.sol:13:21: Error: “msg.value” and “callvalue()” can only be used in payable public functions. Make the function “payable” or use an internal function to avoid this error.
uint amount = msg. value ;
^--------^
Somebody please guide me.

1 Like

Hi,
I have to make ‘public payable’.

Zulfi

1 Like