Skip to content

Instantly share code, notes, and snippets.

@chetanyachopra22
Last active September 8, 2020 06:06
Show Gist options
  • Save chetanyachopra22/eb1723350521440b2009c4f135655cf6 to your computer and use it in GitHub Desktop.
Save chetanyachopra22/eb1723350521440b2009c4f135655cf6 to your computer and use it in GitHub Desktop.
A distributted and open lottery Smart Contract on ethereum which ensures total transparency in Lottery Systems which ensures trust in this Lottery Scheme
pragma solidity ^0.4.17;
contract Lottery {
address public manager;
address[] public players;
function Lottery() public {
manager = msg.sender;
}
function enter() public payable {
require(msg.value > .01 ether);
players.push(msg.sender);
}
function getPlayers() public view returns(address[]) {
return players;
}
function pickWinner() public restricted {
uint index = random() % players.length;
players[index].transfer(address(this).balance);
players = new address[](0);
}
function random() private view returns(uint) {
return uint(keccak256(now, players, block.difficulty));
}
modifier restricted() {
require(msg.sender == manager);
return _;
}
}
@chetanyachopra22
Copy link
Author

A decentralized Lottery Scheme where noone controls the Scheme ... it's all about trust in the system.
Redirecting trust from centralized entity to everyone in the system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment