THIS repo is defunct, project moved to a new repo: ethereum-lupi
Decentralised Smallest Number Game on Ethereum
Play a game where each player sends one positive integer in a game round, with a fixed 'bet' amount. The player who sends a unique and smallest number wins the pot. This means if two people happen to send the same number, then the third one gets all the bets regardless the other two number were smaller.
If there is no winner (ie. there is no unique number in the round ) then all players get back their bet.
What number would you put if you were to play this game?
NOTE: It's a work in progress project: there are plenty of TODO and some open questions. Check it below and the comments in code.
Contribution, code review and suggestions are welcome!
- A round is initiated by the first player. And be closed in a future time (closing date).
- Players submit their guess: a positive integer number for the round. A pre-defined guess amount is included to have a stake in the game.
- At the closing date, the round stops accepting further bets and a winner is selected. The winner is defined as the one who picked the lowest number that nobody else has picked.
- At game close the organizer takes a pre-defined fee.
- If there’s a winner, the contract disburses all remaining funds to the winner.
- If there’s no winner, the remaining funds are disbursed to the participants.
Participants send their bet to a 3rd party (oraclize.it) which encrypts it with it’s own secret key. The encrypted version of the bet is sent in to the contract. At a given time - which is specified at the beginning of the round - the 3rd party starts revealing the clear-text bets, one by one. After all bets are revealed, the round is closed.
See also: Detailed Sequence Diagram
There are a number of known issues with this approach. See ongoing discussion in wiki about potential alternative solutions to keep bids secret until end of the round.
- Ethereum CLI
- nodejs
- node version manager:
npm install -g n
- install 7.10.0 for ethereum-bridge:
n 7.10.0
- install 8.1.0 for testrpc:
n 8.1.0
- install 7.10.0 for ethereum-bridge:
- numbergame repo:
git clone --recursive https://github.com/szerintedmi/numbergame.git
cd numbergame
npm install
cd ethereum-bridge
npm install
- testrpc (global):
npm run testrpc:install
- if you want to run testrpc in a docker container:
npm run testrpc:docker:build
- if you want to run testrpc in a docker container:
- truffle (global):
npm run truffle:install
npm run testrpc:start
npm run bridge:start
npm run truffle:migrate
npm run dev
- An improved and customized Ethereum explorer fork if you want to browse the local chain:
npm run explorer:start
TODO:
- When contract .sol changed then both testrcp and ethereum-bridge need to be restarted. Truffle migrate won't deploy the new version.
- dockerize (Dockerfiles + docker-compose config)
truffle test
(work in progress)
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.