-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lottery.sol
39 lines (26 loc) · 878 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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
contract Lottery {
uint256 totalNumberOfParticipants=2;
uint256 randomNumber = 4;
uint256 winnerIndex;
address winner;
address[] participants;
function bet() external payable returns(bool status){
//20000000 gwei
require((participants.length<=totalNumberOfParticipants) && (msg.value == .02 ether));
participants.push(msg.sender);
return true;
}
function pickWinner() external returns(address){
require(participants.length == totalNumberOfParticipants);
winnerIndex = randomNumber%2;
winner = participants[winnerIndex];
payable(winner).transfer(address(this).balance);
reset();
return winner;
}
function reset() internal {
delete participants;
}
}