30 min to create your first Blockchain app with Typescript & Deku

By Gauthier Sebille

In this tutorial, we demonstrate how to create a parametric blockchain with Deku-P, using the Deku TypeScript-SDK. To do so, we are going to create a state machine using Typescript, execute it within Deku blockchain, and interact with it!

Prerequisites

Running Deku

  1. Install Nix by following the official guide. Additionally, you must enable the flakes feature:
 echo 'experimental-features = nix-command flakes' >> /etc/nix/nix.conf

Nix automatically installs all the dependencies and devtools needed for development, including Tilt, Docker, etc.

Note: Nix is the tool used by marigold to create reproductible environment, other distribution models will be available for the release

  1. Install direnv and don’t forget to “hook direnv to your shell”

  2. You can clone the github directory and use the branch doc/deku-pTutorial, on your terminal type:

$ git clone https://github.com/marigold-dev/deku.git 
$ cd deku
$ git switch arthur/doc/deku-pTutorial
$ direnv allow
$ dune build

You can follow our readme on how to compile Deku.

Init empty typescript application

  • We will use Typescript as a main language for our blockchain application. Create the folder for your new project within the examples folder, in the terminal it looks like:
$ cd examples
$ mkdir myApp
$ cd myApp
$ npm init

npm init will initialize your project it will create a package.json file

  • Run npm install typescript,.
    As a good practice, we will add some compiler settings, within package.json specify to use the tsconfig.json containing all the configurations for your typescript project (created at next step).
"scripts": {
    "build": "tsc --p tsconfig.json",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

Create a new file tsconfig.json at the same level of your previously created package.json

$ touch tsconfig.json

You can copy the content of our tsconfig.json

Install deku-sdk manually by running:

$ npm install "file:../.../sdks/typescript-sdk"
# ../../ because we are in deku/examples/myApp

If you want to learn more about this tutorial, please read our blogpost on Marigold website :point_right: 30 min to create your first Blockchain app with Typescript & Deku

2 Likes

Great tutorial! Looking for more :slight_smile: