Example dApps on Testnet

Obscuro Testnet includes an example dApp to help you better understand how dApps capitalise on Obscuro’s unique privacy features.

Number Guessing Game

A number guessing game is a simple way of showcasing the principles of privacy in Obscuro. The goal of the game is to guess a secret number. Each time an attempt is made an entrance fee of 1 unit of the token is paid (with 1x10^18 units making a single token). If a player correctly guesses the number the contract will pay out all of the accumulated entrance fees to them and reset itself with a new random number.

Consider for a moment how a secret number could be created without divulging it. This is impossible in a transparent, decentralised ecosystem like Ethereum because when the secret number is generated by the smart contract it would be trivial to look up the internal state of the contract and see the secret number. OK, so let’s imagine the internal state of the contract and therefore the secret number is hidden, what happens when players start making their guesses? Using a block explorer to see the attempted guesses in plain view within the details of the transaction immediately provides new players with an unfair advantage and the game is ruined.

Building the guessing game in Obscuro addresses both scenarios described above. The guessing game smart contract generates a random secret number when it is deployed. This number is never revealed to a player or node operator, or indeed anybody because it is generated within a Trusted Execution Environment. And when players make their guesses the transactions carrying the guesses are encrypted and therefore obscured in a block explorer.

How to Play

  1. Start up the wallet extension. Follow instructions here.
  2. For the moment, the Guessing Game includes an ERC20 token (called OGG, short for Obscuro Guessing Game). This is partly because OGG is modified to have a built-in faucet: It allocates tokens to addresses as they make a request to allow other addresses to take tokens from their account.
  3. If you want to see this balance in your wallet, you have to import a new Token with the address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
  4. Browse to the number guessing game. Check you see Network ID: 777 at the top of the game window to confirm you are connected to Obscuro Testnet.
  5. MetaMask will open and ask to connect your account. Click Next then click Connect.
  6. Approve the payment of 1 or more token units to play the game (this will be added to the prize pool) by clicking the Approve game fee button.
  7. MetaMask will ask for your account to sign a transaction specifying the Guess contract address as the approval delegate. This means that you’re giving permission for the game to take the participation fee. Click Confirm. Once approved you will see a confirmation popup. Click OK.
  8. Now you can play the game by typing your guess into the secret number field. Click the Submit guess button.
  9. MetaMask will ask for your account to sign a contract interaction (your guess). Click Confirm. Note how the data presented by MetaMask to you is not yet encypted. That happens when MetaMask signs the transaction and sends it to the wallet extension “network”, allowing the wallet extension to encrypt it before it leaves your computer.
  10. Open MetaMask to check the progress of your guess transaction in the Activity tab of MetaMask. Wait a few moments for it to change from pending to complete.
  11. The game should show you two messages, one confirming the success of the Approval transaction, and the second confirming the result of the guess attempt (whether correct, wrong, warmer or colder than the last guess).

Once the guess transaction is completed you can check the guess transaction on ObscuroScan:

  1. In MetaMask click on the transaction to open it then click Copy Transaction ID. Open ObscuroScan.
  2. Paste your copied transaction ID into the search box to find your individual guess transaction. Note how the transaction data visible to everyone is encrypted in the field EncryptedTxBlob and how (for now) the transaction is decrypted to allow developers to confirm correct behaviour of the network.
  3. You can see your guess as the number at the right hand end of the input value in a hexadecimal format, e.g. a guess of 99 is shown as 63.

Known Issues and Limitations

  1. When making a guess nothing appears to happen. MetaMask shows a failed transaction in the Activity tab for the guess submission.
    • Cause: the guessing game has been reset between this and your previous guess. As a result your nonce is out of sequence.
    • Workaround: reset your MetaMask account data in MetaMask using the option Settings > Advanced > Reset Account

Next Steps

Now you have enjoyed playing the guessing game you are invited to make it even better! Go ahead and fork the guessing game code in this GitHub repository and bring your own contributions to Obscuro Testnet. Of course, you are free to deploy any smart contract to the testnet.