Skip to content

cranklin/crankys-lottery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

crankys-lottery

Basic Ethereum Lottery Smart Contract using https://www.pingchain.co for scheduled execution

Demonstration for https://cranklin.wordpress.com/2018/02/12/lets-build-an-ethereum-lottery-contract-with-scheduled-triggers

Disclaimer: This solidity contract is imperfect. I do not recommend uploading this contract and running your own lottery. This is for demonstration purposes only! This sample lottery contract should not be uploaded. I cooked this up really quick for educational purposes. You'll find that it costs a lot of gas to run, the random number picker isn't perfect, and some features are missing. (Pseudo)Random number generators in smart contracts are not a simple task. Deterministic generation of a pseudorandom number on a public blockchain while preventing it from being manipulated or guessed is obviously difficult to secure. Current block hashes are unknown (the miner hasn't mined the block yet). Block hashes are only known for block heights: n-256 to n-1 where n is the current block height. The rest are 0. In this system, I stored the contract construction block height for its hash to be determined at a later transaction (state change). Each transaction (state change) stores that transaction's block height and keccak256 hashes the concatenation of the previously stored block height's hash with the latest concatenation. The final transaction (drawWinner) concatenates its n-1 block hash and performs a final keccak256 hash before calculating its modulo to the number of entries. It's a quick/naive approach to a complicated problem. And you probably should not actually run a lottery… it’s probably illegal where you live

About

Basic Ethereum Lottery Smart Contract

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published