"Guess Which Hand?" is a smart contract game where a player and a computer pick a choice of 'Left' or 'Right. If the player picks the same move as the computer the player wins. If not, the player loses.
This game is implemented using a smart contract within the Ethereum blockchain. When playing this game, the player will run first run a python script where they pick their move and a password; then is provided a key (combination of the move and password) and a hash of the key via SHA-256.
Once receiving the key & hash, the player will first input the hash value into the smart contract when making their move. When ready to reveal the answer that the computer made, the player will have to input the key provided from the python script. The smart contract will hash this plaintext key via SHA-256 and verify that it is the same hash provided when the player made their move, then set the value of the winner!
- Clone the repository.
https://github.com/cameronlxu/GuessWhichHand.git
-
Install MetaMask on your browser (I used Chrome), and be log in.
-
Add ether in the account, either through a Faucet or Ganache
-
Open up the Remix IDE.
-
Import the
game.sol
script.
- Run the python script
generateMove.py
:
python3 generateMove.py
- Enter a move "L" or "R", then enter a custom password:
-
Compile & deploy the smart contract on the Remix IDE.
-
Regsiter your player:
- Copy the hash from the python script results and paste it into the
gamePlay
function (including the quotes):
- Copy the plaintext key from the python script and paste it into the
showAnswer
function (including the quotes):
- Find out if you won or not!
If there are any issues with this bot, please feel free to contact me at: cameron.lau@sjsu.edu!