1

I have looked at the other posts with similar warning but I do not see how they apply to my context.

This is the exact line that is causing the error:

players[index].transfer(this.balance);

which is inside of this function:

function pickWinner() public {
  require(msg.sender == manager);
  uint index = random() % players.length;
  players[index].transfer(this.balance);
  players = new address[](0);
}

I am not sure if I should understand this literally, because I have not seen any documentation of what to use in lieu of balance.

1

this is typecast as a contract. Earlier compilers did the conversion to type address implicitly the way you wrote it. Newer compilers want it done explicitly.

players[index].transfer(address(this).balance);

That's it.

Hope it helps.

1

this refers to the contract instance itself, which means it is of type contract.

As of solidity 0.4.21, you need to cast this to type address to access the member functions of that type, such as balance.

Try:

  players[index].transfer(address(this).balance);
0

You would need to make two changes. first,

address payable[] public players;

sencond,

players

[index].transfer(address(this).balance);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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