Small game that uses Ethereum ledger to store states and ensure that players don't cheat.
- Popular pencil game from good oll' times -
Sticks & Squares
. - All logic is held by smart contracts, frontend only handles the drawing part.
- MetaMask for user-friendliness is integrated.
Date | Maximum possible mark |
---|---|
2359 5-th March | 10.0 |
Lets look at the source code structure under src
folder:
- contracts - Solidity code.
- static - Frontend code and resources lie here.
- migrations - Contract deployment code.
- SubDockerfile - Launches the cite docker-machine.
- run.sh - Script that launches the server.
- static_server.py - Simple server, that serves static.
- truffle.js - Configuration file, for deploying using truffle framework.
- conf.py - Configuration file for Gunicorn.
- requirements.txt - Dependencies, for launching our python code.
- vendor - under this folder, the external libraries and files lie. I use:
- I use
bootstrap
package for some styles and minor view modifications. jquery_1.12.4.js
, the standard lib for working with DOM elements.web3.js
for connection to Ethereum network.- I make use of
glitch.js
, tiny lib, to make nice logos. - And finally,
truffle-contract.js
custom library from truffle to wrap Solidity contracts in JS.
- I use
The system works as follows:
- Running
docker-compose
command will launch two docker-environments:- ledger - Here the
ganache
Ethereum test-net will be launched. - cite - The simple Flask server will launch, serving our web-game.
- ledger - Here the
- When the cite image, will be build, it will:
- Pull some dependencies.
- Compile contracts.
- Deploy contracts to test-net, that is in separate container.
- Launch python server on Flask, that will serve our frontend logic.
Lastly, let's add a little bit, on how it works:
- Contracts hold the logic.
- Migrations contract is needed to correctly deploy code -> nothing interesting here.
- Math - Small math library that I'm using.
- Rules - The logic of the game.
- TwoPlayerGame - Core logic for game. Manipulates low-level game functions.
- The StickGame contract represents the game itself. It extend the TwoPlayerGame contract, and provides higher level function for game handling.
- Fronted is primitive.
- No logic, just updates the screen.
- Based on callbacks(solidity events), that receives from the ledger.
- Everything is served under Docker.
- One image, creates the ledger using
ganache-cli
. - Other one, which is based on the first image, serves the web-page(No logic there, just for convenience).
- Also it's duty to compile, and upload Smart-contracts.
- One image, creates the ledger using
In order to start everything, a little bit of preparations are required:
-
Since I tried to make the game, as most user-friendly as possible, we are using MetaMask, to communicate with game. Or more precisely, we need MetaMask's web3.js instance, to easily confirm our transactions, that we send to our test net.
So in order, for everything to work correctly, follow this steps:
- Download Google Chrome browser.
- Install the MetaMask browser extension.
- The icon will show in the top-right corner of the browser(where other extensions are).
- Click on it, and create account.
- Click the menu that shows "Main Network" and select
Localhost 8545
.
-
Install the
docker
thing. -
Then, at long last, let's run dis game.
- Assuming you have git run in terminal
git clone https://github.com/NumenZ/LittleBritten
, or, well, just somehow get the code part of current project. - Now, we need to get a small information from our MetaMask account, in order for us, to launch test-net correctly:
- Finally, run
docker-compose up --build
.
- Assuming you have git run in terminal
-
As a last step, open your Google Chrome browser at 'http://127.0.0.1:8080', and enjoy the game.
It must look something like this.
In case, you don't know the rules, check them here.
-
2 points - Write simple working example, with simple web-server and fronted.
-
2 points - Implement the game, with nice GUIs and Smart-Contracts backing up the logic.
-
3 points - Connect front-end with the back-end logic.
-
2 points - Make all configuration as simple as possible, using
Docker
,MetaMask
, file-serving, etc. -
1 point - Write this
ReadMe.md
with all explanations.