Skip to main content

Build the counter DApp

The focus of part 2 of this tutorial is on using the tools that a developer needs to create Midnight DApps. To that end, the example uses an extremely simple contract, which simply defines a counter and a circuit to implement it. To keep the code short enough to read easily, the counter DApp uses a text-based user interface, omitting the additional complexities of a web interface. Later parts of the tutorial will guide you through the creation of web-based DApps.

Starting with your current directory as the top-level Midnight examples directory (such as midnight-examples-0.1.3), go to the counter DApp example:

cd examples/counter

Notice that counter contains two sub-directories, each of which is a separately buildable project.

  • contract - contains the Compact source for the counter contract, plus a tiny amount of associated TypeScript
  • counter-cli - contains the command-line interface of the DApp and depends on the contract code.

Compile the code

Build both sub-projects at once by running the following command in the counter directory above the two sub-directories:

npx turbo build

Successful output looks like this:

 Tasks:    4 successful, 4 total
Cached:    0 cached, 4 total
Time:    8.49s

If you see this sort of output, you have compiled a Midnight DApp, and you are ready to run it.