'cannot send entire contract amount to account in solidity
I have created a lottery contract where I have stored all participated players in an address array I am getting errors while transferring my contract money to the winner i.e in function winner another error is while converting hash value to uint
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.11;
contract lottery
{
address manager;
address[] public players;
function setManager() public{
manager = msg.sender;
}
function enterLottery () public payable{
require(msg.value > 0.9 ether);
players.push(msg.sender);
}
function random() private view returns(uint){
return uint(keccak256(block.difficulty,block.timestamp,players));
}
function winner() public payable{
uint index = random() % players.length;
players[index].send(address(this).balance);
players = new address[](0);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
