Skip to content

Instantly share code, notes, and snippets.

@michalkotas
Created February 17, 2019 15:07
Show Gist options
  • Select an option

  • Save michalkotas/ac0e0a12f5d367e20240a2e5a18cf057 to your computer and use it in GitHub Desktop.

Select an option

Save michalkotas/ac0e0a12f5d367e20240a2e5a18cf057 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.4+commit.9549d8ff.js&optimize=false&gist=
pragma solidity ^0.5.4;
contract Deposite {
address public owner;
constructor() public {
owner = msg.sender;
}
}
pragma solidity ^0.5.4;
contract Lotery {
address public owner;
address payable[] public players;
constructor() public {
owner = msg.sender;
}
function enter() public payable {
require(msg.value > .001 ether);
players.push(msg.sender);
}
function random() private view returns (uint) {
return uint(keccak256(abi.encodePacked(block.difficulty, now, players)));
}
function pickWinner() public onlyOwner {
uint index = random() % players.length;
players[index].transfer(address(this).balance);
players = new address payable[](0);
}
function getBalance() public view returns (uint) {
return address(this).balance;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function getPlayers() public view returns (address payable[] memory) {
return players;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment