-
You must have NodeJS version 22 installed.
-
Download the latest version of the Compact compiler from the compiler release page and follow the instructions to install it (in particular the instructions regarding permissions that must be set to compile the contracts).
-
Create a directory for the compiler executables, and unzip the downloaded file into that directory.
-
Add the directory to your shell's $PATH.
For example, if you unzipped the Compact compiler in
$HOME/bin/compactc
:export PATH=$PATH:$HOME/bin/compactc
-
Run
npm install
to install all the necessary packages. -
Compile and build the code in the
contract
folder before running the code in thecounter-cli
folder.
In thecontract
folder, run this command:npm run compact && npm run build
Follow the instructions in the documentation to install and launch the proof server.
-
Switch to the
counter-cli
folder and run this command:npm run start-testnet-remote
If you do not have a wallet yet, you will be given the option to create a new one. After getting your address, you can use the official faucet to request coins to deploy a contract on testnet and interact with it.
The contract subdirectory contains:
- the smart contract
- some unit tests to test the smart contract
The contract contains a declaration of state stored publicly on the blockchain:
export ledger round: Counter;
and a single transition function to change the state:
export circuit increment(): [] {
round.increment(1);
}
To verify that the smart contract operates as expected,
we've provided some unit tests in contract/src/test/counter.test.ts
.
We've also provided tests that use a simple simulator, which illustrates
how to initialize and call the smart contract code locally without running a node in contract/src/test/counter-simulator.ts
-
Install dependencies:
cd contract npm install
-
Compile the contract:
npm run compact
You should see the following output from npm and the Compact compiler:
> compact > compactc --skip-zk src/counter.compact src/managed/counter Compactc version: 0.22.0
The compiler will complete very quickly because we've instructed it to skip ZK key generation with the option
--skip-zk
. The compiler's output files will be placed in the directorycontract/src/managed/counter
. -
Build the TypeScript source files:
npm run build
This creates the
contract/dist
directory. -
Start unit tests:
npm run test
After building the smart contract you can deploy it using the project in the subdirectory counter-cli
:
cd ../counter-cli
Install dependencies:
npm install
Build from source code:
npm run build
Import the contract code:
npm run compile-contract
Run the DApp:
npm run testnet-remote
If you want to launch all these steps at once, you can use this command:
npm run start-testnet-remote
The preceding entry point assumes you already have a proof server running locally. If you want one to be started automatically for you, use instead:
npm run testnet-remote-ps
Then follow the instructions from the CLI.
If you did not previously create and fund a Midnight Lace wallet, you will need to do so. Funds for testing can be requested from the official faucet.
You can find more information in part 2 of the Midnight developer tutorial.