此代码在remix上的版本0.4.24上运行,但在版本0.5.0+上未运行,我也尝试在Windows 10上使用松露编译它,这也给出了异常。
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()
,但这并不能解决错误
答案 0 :(得分:2)
感谢上帝,我发现了我所缺少的。 坚固度0.5.3: 地址类型有两种:地址和应付地址:与地址相同,但其他成员可以转移和发送。 enter link description here
创建“地址可支付的玩家数组” 例如应付地址[]公共参与者; 还将getPlayers()返回数据类型更改为地址播放器[]