-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLottery.sol
39 lines (28 loc) · 916 Bytes
/
Lottery.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pragma solidity ^0.8.0;
contract Lottery{
address public owner;
address payable [] public players;
address payable public winner;
constructor() public{
owner = msg.sender;
}
modifier Owneronly{
if(msg.sender == owner){
_;
}
}
function deposit() public payable{
require(msg.value >= 1 ether);
players.push(payable(msg.sender));
}
function RandomNumber() private view returns(uint){
return uint(keccak256(abi.encodePacked(block.timestamp,block.difficulty,block.number)));
}
function pickWinner() Owneronly public{
uint randomnumber = RandomNumber();
uint index = randomnumber % players.length;
winner = players[index];
winner.transfer(address(this).balance);
players = new address payable [](0);
}
}