-
Notifications
You must be signed in to change notification settings - Fork 11
/
Lot_Contract.sol
40 lines (35 loc) · 1.26 KB
/
Lot_Contract.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
40
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Lottery{
//manager is in charge of the contract
address public manager;
//new player in the contract using array[] to unlimit number
address[] public players;
function lottery() public {
manager = msg.sender;
}
//to call the enter function we add them to players
function enter() public payable{
//each player is compelled to add a certain ETH to join
require(msg.value > .01 ether);
players.push(msg.sender);
}
//creates a random hash that will become our winner
function random() private view returns(uint){
return uint (keccak256(abi.encode(block.timestamp, players)));
}
function pickWinner() public restricted{
//only the manager can pickWinner
//require(msg.sender == manager);
//creates index that is gotten from func random % play.len
uint index = random() % players.length;
//pays the winner picked randomely(not fully random)
payable (players[index]).transfer(address(this).balance);
//empies the old lottery and starts new one
players = new address[](0);
}
modifier restricted(){
require(msg.sender == manager);
_;
}
}