Ethereum coin flipper is a decentralized app that enables 2 participants to perform a winner-takes-all pseudo-random coin flip. This is how it works:
- A new instance of a coin flip contract is created
- A participant (player 1) deposits a certain amount of ethereum to the contract
- A second participant (player 2) can then accept the terms of the contract by depositing the same amount of ethereum to the contract
- The virtual coin is flipped and the amount of ethereum in the smart contract is deposited to either player 1 or player 2 depending on the outcome.
Currently, a demo is live on the Ropsten Test Net here. Use MetaMask or Mist to execute the transactions.
- Install Truffle globally
$ npm i -g truffle
- Clone repository
$ git clone https://github.com/HarmvZ/eth-coin-flipper.git
- Go in project folder and fetch dependencies
$ cd eth-coin-flipper
$ npm i
- Run Truffle development console
$ truffle develop
- Compile and migrate contracts
> compile
> migrate
- Start development server (run this in a new shell)
$ npm run start
- Now you can use your browser and MetaMask to start flipping coins on http://localhost:3000
- Fix Material Design Lite number input
- Streamline contract interaction by combining transactions: CoinflipCollection.addNew() + Coinflip.makeWager() and Coinflip.acceptWager() + Coinflip.resolveBet()
- Add players
- Improve randomness
- Add minimum wager amount
I created this app to learn more about developing on the Ethereum VM.
This project is created with the official Truffle React box. The coin flip smart contract is based on this example by Decipher Media.