Tictactoe game on Ink, substrate chain

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:

  1. Substrate and Ink are as of now on Rust lang. We need to install the Rust language, Cargo package manager and Substrate framework:

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).

3. Next process would be to install Ink :

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.

This is more like the Truffle Ganache thing on Ethereum Platform. There will be blocks which are been validated. It would look something like:

Fig: blocks being produced by node in terminal.

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

Fig: Polkadot UI 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

It will generate few files and folders like:

Fig: Standard structure of contract

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:

./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,

Ankit Raj

--

--

Blockchain Engineer | Distributed system | Ex- Red Hat | Ethereum foundation grantee

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ankit Raj

Blockchain Engineer | Distributed system | Ex- Red Hat | Ethereum foundation grantee