Showtime – ready to play?

Let’s imagine a scenario where we have two players who are willing to play. We will use a different account for each player from those previously imported into MetaMask. Afterward, register the first player with details (name, phone number) by filling in the Add Player form in the game interface, and clicking Submit. A popup will open up in MetaMask, allowing you to submit the transaction. At any time, you can check the transaction status in MetaMask. Wait until it’s marked as Successful:

Then, switch between MetaMask accounts and repeat the same operation to add the second player. Note that each player is identified by their wallet address.

Great! Now, as you have two registered players, you can make them join the Tontine game. Successively, for each account, press the Submit button under join game label:

This time, you’ll get a MetaMask popup showing that you are sending 2 ether to the game (as we fixed that amount in our Drizzle code). Confirm the deposit for both players:

In the same way, you can ping the contract for each player.

I'm sure you’ve noticed that once the join or ping action is dispatched, Drizzle will update the ContractData components (player and Tontine details) automatically without refreshing the whole page as soon the transaction is validated.

As we did in testing, you can increase the time in the trial process to try the elimination feature. From a new Terminal, launch Truffle’s console: truffle console.

This will spawn an interactive console connected to Ganache. We use it to run the following RPC calls:

web3.currentProvider.send({ jsonrpc: "2.0", method: "evm_increaseTime", params: [90000], id: 1 })
web3.currentProvider.send({ jsonrpc: '2.0', method: 'evm_mine', params: [], id:1 })

You can check the block’s timestamp using web3.eth.getBlock("latest").timestamp.

After increasing the time by more than 24 hours, both players can be eliminated. Consider eliminating the second player using the elimination form here:

Once the player is eliminated, Drizzle will automatically display the details at the bottom of the web page:

The remaining player should be able to claim and get the due reward (4 ether).

During this tryout, we ensured that the Tontine game is working as expected!

As you can see, we have built a minimalist DApp frontend for the game. This choice was intended to give you the chance to elaborate on the design and create a complete frontend for the game. Count it as an exercise for you. You can even build a small Whisper-based chatroom module for the players. For your information, Whisper (not supported by Ganache) is a direct-messaging protocol in the Ethereum network, and it’s fun to work with. I’ll be waiting for your pull requests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset