Skip to the content.

Part 2: Setup

The code for this tutorial is available on github.

Pre-requisite

This tutorial uses Typescript and nodejs, if you don’t have nodejs installed, you can follow the instructions here.

Bitcoind

First you need to have bitcoind installed. You can also use a docker container if that is more convenient for you, but the instruction in this tutorial will assume a locally installed one (note that it shouldn’t make that big a difference).

Setup

Start by initializing an npm project:

npm init

Set the entry point to index.ts:

entry point: (index.js) index.ts

Fill the rest however you want.

We will then install some dependencies:

npm install bitcoin-simple-rpc inquirer inquirer-datepicker uuid --save

Then install the DLC library as well as the base CFD library (useful for some utility functions):

npm install github:cryptogarageinc/cfd-js#v0.2.5 github:cryptogarageinc/cfd-dlc-js#v0.0.8

Add some dev dependencies (you can skip those if you prefer to use plain JavaScript):

npm install @types/inquirer @types/node ts-node typescript --save-dev

We also add a script to launch the application in the package.json:

  "scripts": {
    "example": "ts-node index.ts"
  },

Finally, create the following tsconfig.json file in the root folder:

{
  "compilerOptions": {
    "target": "ESNext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "module": "commonjs"
  }
}

In the third part we will finally start coding!