Addresses
TypeError:未檢測到推送作為地址應付動態數組的函式
我正在嘗試將經理地址添加到播放數組中。我收到以下錯誤:
TypeError:在應付地址中進行參數相關查找後,成員“推送”未找到或不可見
$$ $$儲存參考
這是我的程式碼:
pragma solidity ^0.7.1; contract Lottery{ address public manager; uint public value; address payable[] private players; constructor() payable { manager = msg.sender; value = msg.value; } function enter() public payable { require(value > 0.01 ether); players.push(manager); } function random() private view returns (uint){ return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players))); } function pickWinner() public{ uint index = random() % players.length; players[index].transfer(address(this).balance); } }
有任何想法嗎?謝謝!
您正在嘗試將非支付地址推送到數組:
manager
is notpayable
。您需要將類型更改manager
為address payable
:address payable public manager; function enter() public payable { require(value > 0.01 ether); players.push(manager); }
只需將
msg.sender
(例如players.push(msg.sender)
)添加到數組中就可以了,因為它已經是payable
.