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 TypeScriptcounter-cli- contains the command-line interface of the DApp and depends on thecontractcode.
Compile the code
- In the
contractfolder, 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.
- Switch to the
counter-clifolder and run the application:
npm run start-testnet-remote
This starts the DApp and connects to a remote Midnight testnet node.
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
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
- In the
contractfolder, run this command:
npm run build
This creates the contract/dist directory.
- Start unit tests by running:
npm run test
- In the
counter-clifolder, run this command:
npm run build