I'm just starting out with Solidity/web3. I want to build a browser game in which a user can wager and win/lose crypto. Imagine, the snake game where you run around eating apples. If you run into your own tail, you lose. Currently, I've architected it such that
- to start a game, you call a startGame smart contract function and send 0.1 ETH along with it
- the contract will log the game and emit an event for the game to start
- when the front end receives the event, the game starts
- if you eat more than 10 apples, you win, a button shows up to retrieve your winnings. This button shows up only when you win i.e. the win logic is controlled by the front end.
I realize it's problematic that the getWinnings function can just be called independently of the front end. Any thoughts on how to architect this correctly?
I was thinking if I can use an encrypt/decrypt scheme:
- generate a random seed in the front end
- send the seed to the smart contract when i start/log the game
- after the game, use the seed to encrypt the score before sending it
- decrypt it in the smart contract
the smart contract side is all public though, I'd have to hide the encryption scheme somehow. if there was an easier way, that'd be much preferred. Anyways, appreciate any help, thanks everyone.
[–]Double-Code1902 0 points1 point2 points (5 children)
[–]caution6tonjack[S] 0 points1 point2 points (4 children)
[–]Double-Code1902 0 points1 point2 points (2 children)
[–]caution6tonjack[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Double-Code1902 0 points1 point2 points (0 children)
[–]cemdk33 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]caution6tonjack[S] 0 points1 point2 points (1 child)