Session given at NextBuild 2017, XPDays 2017, AppDevCon 2018, and as a webinar.
To show you the power of Blockchain we are going to demonstrate how you can make an application that can be trusted by anyone. We will create a game where cheating is impossible. The game is a live guessing game. Anyone can set a challenge consisting of a question, its answer, and prize money. The first person to give the correct answer wins that challenge, and takes away the prize money.
The game is called ÐQuestions1. It consists of a web based UI, and a smart contract on the Ethereum blockchain where you would normally find the backend. This smart contract ensures that not even us can cheat the game.
We won’t bore you with PowerPoint bullet lists from hell, nor will we simply use
handwaving to explain the concepts. We will go on stage and actually program
the game during this session. We’ll show you that even especially in
immature development environments you can rely on good coding practices such as
Test Driven Development and Continuous Integration.
We intend for you to walk away from this session not only knowing how to start developing a Blockchain app, but also wanting to!
Prerequisite: you need a working Node.js environment.
If you want to run this game, after cloning this repo please do the following:
- Run
yarn install
on the root level - Run
yarn truffle develop
to start the Truffle development console- In the development console, run
migrate
to deploy the smart contracts
- In the development console, run
- In the folder
web-app
, runyarn start
to run the web server. - Install the browser extension MetaMask and open it.
- When prompted, choose the option to "Import your existing wallet using a 12 word seed phrase"
- Enter the 12-word seed phrase that Truffle generated. It should be in the output of Truffle from step 2 above. Important: only use this on a local Truffle network, never on a production Ethereum network or you will surely lose funds.
- Switch from the Main Network to a Custom RPC network with url:
http://localhost:9545
Now browse to http://localhost:3000 and you should see the game interface.
Please note that every time you restart truffle develop
, you need to reset
the MetaMask account. To do that, you open the MetaMask dialog and open its
settings by clicking the top-right icon and choosing "Settings" from the menu.
Then go to the "Advanced Settings" and click the "Reset Account" button. The
reason for this is that MetaMask keeps track of what the transaction nonce
should be, but Truffle starts from the beginning when you start it, so then
the nonces don't match.
1 ÐQuestions, pronounced "five-hundred questions", is the decentralized version of the game 500 Questions. Please not that 'Ð' is used generally for ÐApps (decentralized apps), and that 'D' is the roman numeral for 500. Clever, huh?!