Reputation: 31
this code is running on version 0.4.24 on remix but not on version 0.5.0+, I also tried to compile it with truffle on Windows 10 which also gives the exception.
pragma solidity ^0.5.0;
contract lottery {
address public manager;
address[] public players;
constructor() public{
manager = msg.sender;
}
modifier restricted(){
require(msg.sender == manager);
_;
}
function enterLottery() public payable {
require(msg.value > 0.01 ether);
players.push(msg.sender);
}
function random() public view returns(uint) {
return uint(keccak256(abi.encodePacked(block.difficulty,now,players)));
}
function pickWinner() public restricted{
uint index = random() % players.length;
address winner = players[index];
players = new address[](0);
winner.transfer(address(this).balance);
}
function getPlayers() public view returns(address[] memory){
return players;
}
}
winner.transfer(address(this).balance);
isn't working. I also made the pickWinner()
payable but that didn't fix the error
Upvotes: 1
Views: 153
Reputation: 31
Thank God, I found what I was missing. In solidity 0.5.3: The address type comes in two flavors, address and address payable: Same as address, but with the additional members transfer and send. enter link description here
create "address payable array of players" e.g. address payable[] public players; also change getPlayers() return datatype to address players[]
Upvotes: 2