This is a tic-tac-toe game developed on top of Ethereum blockchain. To achieve full decentralization, deployment is done in two areas:
- Smart contracts - Ropsten test net
- Web UI - IPFS
- First version will be 3x3, but then expanding to 4x4, 5x5 and beyond
- The game should be only played in multiplayer
- After each game, the winner is incentivised with TTTP(Tic-Tac-Toe Points) and TTTT(Tic-Tac-Toe Tokens) depending on oponents power and win score
- TTTP(Tic-Tac-Toe Points) - are used to hold a player's playing power and is used in the match-making process
- TTTT(Tic-Tac-Toe Tokens) - are used to buy several items in the game(you can buy more time, reduce the time of the other player between rounds, or buy other kinds of perks I can't think of now)
- Match-Making system implemented by a Smart Contract which joins players together based on their TTTP
Match-Making Start Contract
also issuestopic token
for Whisper connection in full darkness- Chat is also available for players to communicate if they want
- Each player can set a name which might be saved on another smart contract - this consumes TTTT(you can also update it)
- Weekly or monthy leader boards? They get more points?(need to find places where to spend those new points)
Below are two approaches for implementation and we'll try each one to see how they behave to get an in depth understanding of the underlying infrastructure and the pros/cons of each approach
- Whole logic of the game is stored inside a smart contract and every time a move is made, a transaction confirms that move and saves the state
- Communication between nodes is done via Whisper using full darkness
- Full darkness is achieved by way of communicating via a private topic between the two players which is issued by the
Match-Making Smart Contract
- Nodes Communicate between each other the following:
- State of the game
- When each players makes a move
- When the game is over and they have to send in the result to the blockchain
- When they want to communicate on the chat
- When the time is increased/decreased of self/oponent via buying it with TTTT
- etc
-
Instead of sending each transaction, we only send the state of the game when the game is over - checking that players did not cheat is done via both players sending the state of the board thus if either changed it in their favor we will spot it - this will also remove the need to approve each transation via MetaMask and will also not slow down the game as transactions take a while on the Ropsten test net unlike a local private net where they are almost instant
-
Communication between nodes is done via Whisper using full darkness
-
Full darkness is achieved by way of communicating via a private topic between the two players which is issued by the
Match-Making Smart Contract
-
Nodes Communicate between each other the following:
- State of the game
- When each players makes a move
- When the game is over and they have to send in the result to the blockchain
- When they want to communicate on the chat
- When the time is increased/decreased of self/oponent via buying it with TTTT
- etc
-
Players who don't send in the game state in certain time period will loose both TTTT and TTTP(more than normal) - this is to counter scenarios where people are loosing a game and they do not want to loose points
Implementation is done in several stages to achive faster feedback from an almost complete game. Each stage should be playable while the next stage adds new features
Run a test net locally and play against the computer
- Install ganache for desktop from https://github.com/trufflesuite/ganache/releases
- This will start on port http://127.0.0.1:7545, application is already configured to run on it
- Go to
Settings -> Chain
and setGAS LIMIT
to30000000000000
andGAS PRICE
to1
- Now you're good to go
- Navigate to https://gateway.ipfs.io/ipfs/QmSG1xr3vSMtdNGeg3Kcf5jMfwaWq16JCAcpUaQbgPsq4q/#/tic-tac-toe-stage-1
- Make sure you do not run it in a browser that has MetaMask installed as it will no work as intended!
Note: It's still early stages of development, so few validation might not be in there
Connect to the game using MetaMask on the Ropsten test net and play against the computer
Run a test net locally and two game instances. In each instance pick an account from the list and start playing between the two
- run
geth --shh --datadir=.\chaindata --rpc --rpccorsdomain="*" --rpcport="8545" --minerthreads="1" --nodi scover --maxpeers=0 --unlock 0 --rpcapi="eth,net,web3,personal,miner,shh"
- you can attach to that node
geth attach http://127.0.0.1:8545
and issue commands likeminer.start()
orminer.stop()
such that when you have pending transactions they get completed(if the miner is running) - or you can simply install ganache for desktop from https://github.com/trufflesuite/ganache/releases (recommended)
- This will start on port http://127.0.0.1:7545, application is already configured to run on it
- Go to
Settings -> Chain
and setGAS LIMIT
to30000000000000
andGAS PRICE
to1
- you can attach to that node
- Navigate to https://gateway.ipfs.io/ipfs/QmWeKXP5yRBeeogmr7uSaKLVwmnjoZtwycbdenwVqQt9hA/#/tic-tac-toe-stage-3
- Make sure you do not run it in a browser that has MetaMask installed as it will no work as intended!
- If IPFS does not pull it, it means that the cache on some nodes is gone and my PC is offline(which it shouldn't be). You can ping me on slack or run
ng serve
in the root folder. Then open uphttp://localhost:4200/#/tic-tac-toe-stage-3
- You should have two browsers open! This is a multiplayer game!
- Go to
https://remix.ethereum.org
and copy over the smart contract found insrc/contract/tic-tac-toe-stage-1/TicTacToeStage3Contract.sol
- Deploy the contract
- Copy and paste the contract address in the
Contract address
field of the game.(in both browsers) - Select your player(in each browser) and hit
Start game
. The game will match you with other players signed for a game(in this case the two players you signed) - Play the game until somebody wins or looses(validations are not in place, so don't double click and any of that stuff)
- Thanks!
Connect to the game using MetaMask on the Ropsten test net and wait for an opponent to come online. Play it as a 1v1 accross the globe.
- we might be able to achive cross-player communication using the Whisper protocol by using
web3.shh
Here we test the deployment to IPFS of https://github.com/aoancea/dapps-auction-angular-client. It's a test to see if and how a dapp needs to be deployed in order to also work properly
- Install ganache-cli for desktop and run it with 5-10 accounts on http://127.0.0.1:7545
- Navigate to https://gateway.ipfs.io/ipfs/QmQqNmXSWU2c3BxyeZfiHG6S5GngHUqznh8XtFyXMyyvtH
This is a simple page that tries to implement a crowdfunding campain. You are able to transfer money to my account through a smart contract using MetaMask connected to the Ropsten public test net.
- It's a web application fully hosted on IPFS meaning that it has no single point of failure and it can only go down if all nodes in the IPFS network go down which is very unlikely
- It's a web application on which nobody has access anymore in terms of changing any of its code. It's fully immutable
- It's application that connects to the Ropsten public test net through MetaMask and accepts ETH to send to my account
- It's a decentralized application hosted decentralized
- Access https://gateway.ipfs.io/ipfs/QmSv8Th6MQLv8BsTot43KnDydMQi9kcfecPQgV8nNzcRr8/#/raise-funds - there is a bug that makes the UI not really refresh when actually needed. To fix this just click on the text box from time to time and it will refresh the entire UI (do not access the other 2 links as they might crash)
- Install MetaMask from https://metamask.io/. It comes with a built in account.
- Select the
Ropsten
test net from upper left of the pop-up which opens when you click on the MetaMask fox icon -> you are now connected to theRopsten
test net - Hit the
BUY
button to get Ethereum in your account as your current balance is0
- Hit
ROPSTEN TEST FAUCET
and get redirected to the actual site where you'll transfer funds to your accout - You are now on https://faucet.metamask.io/ and hit
request 1 ether from faucet
- Wait until the transaction is processed. You can meanwhile access the transaction hash appearing in the transation section and see what actually happens. Here is an example https://ropsten.etherscan.io/tx/0x830c212282ce436cf86916606417e1dd85d728c7acad426f19736590d7295080
- Now that you have earned
1 ETH
go back to https://gateway.ipfs.io/ipfs/QmSv8Th6MQLv8BsTot43KnDydMQi9kcfecPQgV8nNzcRr8/#/raise-funds - Enter a value between 0 and 1 inside the text box and hit
Transfer
- Check your MetaMask extension icon as you'll have to approve the transaction
- Hit
Submit
and click on the transaction generated in theSent
tab if you want to inspect it like when you aquired1 ETH
- Wait until the transation is completed(remember to click from time to time on the text box in the page so it gets refreshes - it's about that annoying bug)
- You have now succesfuly transfered me ether,
Thank you and come again