A simple counter smart contract demonstrating Midnight's zero-knowledge proofs.
- Node.js 22+:
node --version - Docker:
docker --version - Compact Compiler: Install with:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | sh source $HOME/.local/bin/env
npm install
cd contract && npm run compact && npm run build
cd ../counter-cli && npm run buildIn a separate terminal (keep it running):
docker run -p 6300:6300 midnightnetwork/proof-server:6.1.0-alpha.6 -- midnight-proof-server --network previewcd counter-cli
npm run previewChoose one:
- Option 1: Build fresh wallet (will need funding)
- Option 2: Enter mnemonic manually
- Option 3: Use mnemonic from
.envfile (pre-configured)
- Copy your wallet address from the CLI output
- Visit Preview Faucet
- Request tokens and wait ~2 minutes
- Choose Deploy to create a new counter contract
- Use Increment to increase the counter
- Use Display to view current value
├── contract/ # Compact smart contract
│ └── src/counter.compact
├── counter-cli/ # CLI application
└── .env # Wallet mnemonic (pre-funded)
| Service | URL |
|---|---|
| Faucet | https://faucet.preview.midnight.network |
| RPC | https://rpc.preview.midnight.network |
| Indexer | https://indexer.preview.midnight.network |
| Issue | Solution |
|---|---|
ECONNREFUSED 127.0.0.1:6300 |
Start the proof server |
compact: command not found |
Run source $HOME/.local/bin/env |
| Balance stays 0 | Use faucet, wait 2-3 minutes |