gpt4 book ai didi

ethereum - Solidity,成员 "transfer"在参数依赖后未找到或不可见

转载 作者:行者123 更新时间:2023-12-04 23:12:36 25 4
gpt4 key购买 nike

使用 Solidity ^0.5.0,
我实际上正在尝试实现在 ^0.4.17 中工作的旧代码,但它在 Remix 上引发错误。
我检查了语法和所有内容,但无法发现问题所在。
任何帮助高度赞赏。

pragma solidity ^0.5.0;

contract Lottery{
address public manager;
address[] public players;

constructor() public {
manager = msg.sender;
}

function participate() public payable {
require(msg.value > .01 ether);
players.push(msg.sender);
}

function pseudoRandom() private view returns(uint){
return uint(keccak256(abi.encodePacked(block.difficulty, now, players)));
}

function pickWinner() public {
uint index = pseudoRandom() % players.length;
players[index].transfer(address(this).balance);
}
}

这是错误消息:

browser/Lottery.sol:22:8: TypeError: 成员“转移”未找到或在参数依赖后不可见
在地址中查找。

玩家[索引].传输(地址(msg.sender)。余额);

^--------------------^

最佳答案

请查看 Solidity v0.5.0 Breaking Changes .

正如所指出的here :

The address type was split into address and address payable, where only address payable provides the transfer function.



看我的回答 here更多细节。

改变这一行:
address[] public players;

对此:
address payable[] public players;

编辑

谢谢smarx! 😄

关于ethereum - Solidity,成员 "transfer"在参数依赖后未找到或不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53499997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com