Chromia
Start Building

22 / 26Part 6: Create the clientBeginner

Prerequisites

This tutorial takes you step by step from preparing your development environment to understanding the code.

First, confirm that your development environment is configured correctly.

Step 1: Install Node.js and set up the project

  1. Install Node.js: Node.js runs JavaScript on the server side. If it isn't on your machine yet, get it from the Node.js website and install it.

  2. Create a project directory: In your terminal, go to the location where your project should live and run these commands:

    shell
    mkdir chromia-book-review-democd chromia-book-review-demo
  3. Initialize a Node.js project: Generate a package.json file with this command:

    shell
    npm init -y

Step 2: Install required packages

With the project in place, install the packages it depends on:

shell
npm install typescript postchain-client readline @types/node
  • typescript: adds TypeScript support.
  • postchain-client: provides the tools you use to communicate with the Chromia blockchain.
  • readline: a core Node.js module for reading user input from the command line.

Step 3: Configure TypeScript

TypeScript reads its settings from a file called tsconfig.json. Generate it by running:

shell
npx tsc --init

You get a tsconfig.json file with default settings, which you can adjust to fit your project.

Step 4: Integrate the code

With the packages installed, you can add the code to your project:

  1. In your project directory, create a TypeScript file called book_review.ts. Leave it empty for now; you will fill it in over the following sections.

  2. Node.js can't run TypeScript directly, so transpile it to JavaScript first:

    shell
    npx tsc

    The compiled JavaScript is written to a book_review.js file.

  3. Run the result with Node.js:

    shell
    node book_review.js

    This runs your code, which interacts with the Chromia blockchain according to what you have written.

Your development environment is now ready: the required packages are installed and TypeScript is integrated into the project. The next section walks through an example client.

Written for this site from Chromia’s public course. Code samples are the course’s own.