Skip to main content

Build the counter DApp

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.

At the root level of the example-counter repository, notice 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

  1. In the contract folder, compile the Compact contract and build:
npm run compact && npm run build

The compact script calls compact compile with the correct paths configured in package.json. The build script compiles the TypeScript wrapper code.

  1. Switch to the counter-cli folder and run the application:
npm run start-testnet-remote

This starts the DApp and connects to a remote Midnight testnet node.

note

The npm scripts use the new compact compile command internally. The deprecated compactc executable should not be used directly. Always use either compact compile or the provided npm scripts.

You should see the following output from npm and the Compact compiler:

Compact version: 0.25.0
Compiling 1 circuits:
circuit "increment" (k=10, rows=29)
Overall progress [====================] 1/1
note

The compiler completes very quickly because you've instructed it to skip ZK key generation with the option --skip-zk. The compiler's output files are placed in the directory contract/src/managed/counter.

Build the TypeScript source files

  1. In the contract folder, run this command:
npm run build

This creates the contract/dist directory.

  1. Start unit tests by running:
npm run test
  1. In the counter-cli folder, run this command:
npm run build