This is the part 1 of making tictacktoe game on Ink and deployed on substrate framework.
Ink is an eDSL to write WebAssembly based smart contracts using the Rust programming language. It’s been crafted by Parity team.
We will discuss a very fast approach to develop smart contract. I am using Linux machine (Ubuntu 18.04LTS/8GB RAM/1TB storage) for development. There are other software per-requisite enviroment like:
- Substrate and Ink are as of now on Rust lang. We need to install the Rust language, Cargo package manager and Substrate framework:
# install rust and update environmentcurl https://sh.rustup.rs -sSf | sh
source ~/.cargo/env
# run rust updates and add WebAssembly target supportrustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
# Install Substrate with the following command:curl https://getsubstrate.io -sSf | bash
2. Smart contracts in Substrate are compiled to WebAssembly (Wasm). To manipulate these files for use on Substrate,one need to install some Wasm utilities like Binaryen ( Compiler infrastructure and toolchain library for WebAssembly), Wabt (The WebAssembly Binary Toolkit), Parity Wasm Utils (Parity specific WebAssemply utilities).
apt install binaryen
apt install wabt
cargo install pwasm-utils-cli --bin wasm-prune
3. Next process would be to install Ink :
cargo install --force --git https://github.com/paritytech/ink cargo-contract
Note: installation of above libraries/packages will take time. So, it’s better to sit with coffee/pizza.
After successful download of all packages , one need to initialize the chain on local machine.
substrate --dev
This is more like the Truffle Ganache thing on Ethereum Platform. There will be blocks which are been validated. It would look something like:
One can also see all these in very good UI dashboard called as Polkadot UI: https://polkadot.js.org/apps/ . Clone it and run locally, open explorer. It will show the dashboard
By this time development and deployment environment has been setup. Now it’s time to write contract and deploy it.
We are going to build tic tac toe game on substrate. For this we gonna use ink for generating boilerplate of substrate smart contract. There is already some code in boilerplate. We will enhance those code
cargo contract new tictactoe
It will generate few files and folders like:
By default ink generate a single contract storage value (bool) which gets flipped from true to false through the flip()
function. We will work on this contract. Usually it is called as flipper contract, but since we are using this bolierplate for another contract. So, we are giving new name as tictactoe
.
Also, ensure we have permissions to run tictactoe/build.sh
:
cd tictactoe
chmod +x build.sh
./build.sh
command will be used to run build after test.
By this time, one has successfully did basic setup with boilerplate for the game. In Part2, we will describe the code and deployment process.
Cheers,