此代码在 remix 版本 0.4.24 上运行,但不在 0.5.0+ 版本上运行,我还尝试在 Windows 10 上使用 truffle 编译它,这也给出了异常。
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);不工作。我也支付了pickWinner()应付款项,但这并没有解决错误