/midnight-skills:example-counterfrom midnight-skills
Generates a complete Midnight Network counter DApp from scratch: compact smart contract, interactive CLI, wallet setup, DUST generation, deploy+interact loop, Docker configs for local/preprod/preview, and tests.
Ships in midnight-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill is the walkthrough for templates/counter-dapp/, the runnable midnightntwrk/example-counter reference DApp (v2.1.1) ported to Ledger 9 in this repo (21 Nov 2026). Upstream had not published a Ledger 9 release at the time: its main still pins runtime 0.15 / Midnight.js 4 / setNetworkId. The template holds every source, config and Docker file; this page explains them. Do not retype the files from here: copy the template, then adapt it (§13).
Get the template:
git clone --depth 1 --filter=blob:none --sparse https://github.com/Kali-Decoder/Midnight-Skills.git
cd Midnight-Skills && git sparse-checkout set templates/counter-dapp
cp -R templates/counter-dapp ../my-counter && cd ../my-counter
npm install
cd contract && npm run compact && npm run build && cd ..
Without a checkout, read any file at https://raw.githubusercontent.com/Kali-Decoder/Midnight-Skills/main/templates/counter-dapp/<path>.
Verified: the contract compiles with compact compile +0.36.1, contract type-checks and builds, and counter-cli type-checks against the installed Ledger 9 packages. The CLI has not been run against a live network.
Primary references:
github.com/midnightntwrk/example-counter — official reference repodocs.midnight.network/guides/deploy-mn-app — official deploy guidedocs.midnight.network/guides/interact-with-mn-app — official interact guidedocs.midnight.network/relnotes/support-matrix — authoritative version compatibility matrixPackage versions below are the Ledger 9.1 set (checked against npm and the support matrix on 21 Nov 2026). Resolve the current tested set from the support matrix before pinning — see references/volatile.md. Never install @latest.
templates/counter-dapp/
├── package.json # npm/yarn workspaces: contract, counter-cli
├── package-lock.json
├── compose.yml # Docker: full local stack (localhost-only)
├── contract/
│ ├── package.json # @midnight-ntwrk/counter-contract (exports dist/)
│ ├── tsconfig.json, tsconfig.build.json, vitest.config.ts
│ └── src/
│ ├── counter.compact # the contract
│ ├── witnesses.ts # CounterPrivateState + witnesses
│ ├── index.ts # re-exports managed contract + witnesses
│ └── managed/ # compiler output (gitignored)
└── counter-cli/
├── package.json # @midnight-ntwrk/counter-cli
├── tsconfig.json, tsconfig.build.json, vitest.config.ts, vitest.setup.ts
├── proof-server.yml # Docker: proof server only (preprod/preview)
├── standalone.yml # Docker: node + indexer + proof server
├── standalone.env.example
└── src/
├── api.ts # wallet, providers, deploy/join, increment, DUST
├── cli.ts # interactive menus
├── config.ts # network config classes
├── common-types.ts, logger-utils.ts, index.ts
└── preprod.ts, preview.ts, standalone.ts, *-start-proof-server.ts
Not included: upstream's test suites (contract/src/test/*, counter-cli/src/test/*) and its eslint/prettier/VS Code configs. The vitest configs are kept so tests can be added.
# Node.js 22.15+ required
node --version
# Yarn 1.x (classic) required
yarn --version
# Docker required (proof server + optional local stack)
docker --version
# Install Compact compiler
curl --proto '=https' --tlsv1.2 -sSf \
https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | sh
source $HOME/.local/bin/env
compact update 0.36.1
compact compile --version
| File | Role |
|---|---|
package.json | Root workspace (contract, counter-cli); scripts test, test:local, env:up/env:down, validate; pins the shared Ledger 9 packages |
contract/package.json | compact (compact compile +0.36.1 src/counter.compact src/managed/counter), build (tsc + copies managed/ into dist/), typecheck. main/types point at dist/, so build the contract before running the CLI |
counter-cli/package.json | preprod, preview, standalone, *-ps (auto-start proof server), typecheck, build |
*/tsconfig*.json | ESM, strict; tsconfig.build.json emits dist/ |
compose.yml, counter-cli/standalone.yml | Full local stack (node, indexer, proof server) on localhost |
counter-cli/proof-server.yml | Proof server only, for preprod/preview |
counter-cli/standalone.env.example | Copy to standalone.env for the local stack |
Image tags and package versions are the references/versions.json set.
contract/src/counter.compactpragma language_version >= 0.28.0;
import CompactStandardLibrary;
export ledger round: Counter;
export circuit increment(): [] {
round.increment(1);
}
Compile it:
# From the contract/ directory
cd contract && npm run compact
Expected output (exact k/rows depend on the toolchain; 0.36.x emits ZKIR v3):
Compiling 1 circuits:
circuit "increment" ...
contract/src/witnesses.tsexport type CounterPrivateState = {
privateCounter: number;
};
export const witnesses = {};
contract/src/index.tsexport * as Counter from "./managed/counter/contract/index.js";
export * from "./witnesses";
counter-cli/src/config.tsNetwork configuration. Ledger 9 / Midnight.js 5: there is no setNetworkId, so each config carries its networkId. Preprod is served by Blockfrost.
Config is implemented by StandaloneConfig (local Docker stack, undeployed), PreviewConfig and PreprodConfig. Each carries networkId, logDir, indexer HTTP/WS URLs, node URL, proof server URL and an optional faucet. contractConfig holds the privateStateStoreName for the LevelDB private-state provider and the zkConfigPath of the compiled contract (contract/src/managed/counter).
Note: local and preview use indexer API v4 (/api/v4/graphql). The old "all networks use v3, do not change to v4" advice is obsolete. indexer.preprod.midnight.network was retired on 9 Oct 2026 (HTTP 410), and rpc.preprod.midnight.network shut down on 18 Nov 2026. Blockfrost URLs contain your token, so don't log them.
counter-cli/src/api.tsCore API — wallet creation (Wallet SDK 2.x), contract deploy/join, increment, DUST management. Ported to Ledger 9; type-checked against Midnight.js 5.0.2 / Wallet SDK 2.0.1.
| Export | What it does |
|---|---|
buildWalletAndWaitForFunds(config, seed) / buildFreshWallet(config) | WalletFacade from a seed (or a new one), sync, wait for funds, register NIGHT for DUST |
createWalletAndMidnightProvider(ctx) | Era-aware wallet and midnight providers from the facade |
configureProviders(ctx, config) | Full MidnightProviders: LevelDB private state, indexer, node ZK config, HTTP proof provider, config: { networkId, ttlSeconds } |
deploy(providers, privateState) / joinContract(providers, address) | deployContract / findDeployedContract with counterCompiledContract |
increment(contract) | callTx.increment() |
getCounterLedgerState(providers, address) / displayCounterValue(...) | Read and decode the ledger with Counter.ledger(contractState.data) |
waitForSync, waitForFunds, getDustBalance, monitorDustBalance | Wallet and DUST helpers |
withStatus, setLogger | CLI progress output and logging |
Key points:
globalThis.WebSocket = WebSocket is required for GraphQL subscriptions (wallet sync) in Node.jsWalletFacade.init() with WalletSeeds.fromMasterSeed(seed); the facade is started with the seeds (wallet.start(seeds))createLedger9WalletProvider / createLedger9MidnightProvider; the old signTransactionIntents workaround is goneproviders.config = { networkId, ttlSeconds } replaces setNetworkIdstate.dust.balance(time); the registration signer returns a Promise (SignSegment)counter-cli/src/cli.tsInteractive CLI with wallet setup, deploy/join, and counter interaction menus. Supports Docker lifecycle via testcontainers. run(config, logger, dockerEnv?) drives three menus: wallet (create, restore from seed), contract (deploy, join by address), and counter (increment, read). Entry points pick the config and call run.
counter-cli/src/)| File | Network | Notes |
|---|---|---|
preprod.ts | preprod | Blockfrost endpoints: export BLOCKFROST_PROJECT_ID first |
preview.ts | preview | No token needed |
standalone.ts | undeployed (local) | Starts standalone.yml through testcontainers; uses the genesis wallet |
preprod-start-proof-server.ts, preview-start-proof-server.ts | preprod / preview | Also start proof-server.yml |
index.ts | n/a | Re-exports api and cli |
# 1. Install deps
yarn
# 2. Compile and build the contract (the CLI imports its dist/)
cd contract && npm run compact && npm run build && cd ..
# → circuit "increment" (compiled by `compact compile +0.36.1`)
# 3. Start proof server (keep this terminal open)
cd counter-cli && docker compose -f proof-server.yml pull && docker compose -f proof-server.yml up
# 4. In another terminal, run the CLI (preprod endpoints are Blockfrost: export a preprod token first)
export BLOCKFROST_PROJECT_ID=nightpreprod...
cd counter-cli && tsx src/preprod.ts
# or with auto-started proof server:
cd counter-cli && yarn preprod-ps
Faucet: https://midnight-tmnight-preprod.nethermind.dev/ (preprod) or https://faucet.preview.midnight.network/ (preview, tsx src/preview.ts, no token needed). Preprod cleared non-cNIGHT DUST registrations on 9 Nov 2026, so wallets register again on first run.
The CLI will:
# 1. Start full local stack with testcontainers (auto-managed)
cd counter-cli && yarn standalone
# 2. This will:
# - Pull Docker images
# - Start node + indexer + proof server
# - Use the genesis wallet (pre-funded)
# - Deploy contract and enter the interaction loop
Note: Standalone mode uses the genesis mint wallet seed (0000...0001) automatically. No faucet needed.
The template keeps the vitest configs but not upstream's test files. After adding tests:
# Contract unit tests (from contract/ directory)
cd contract && npm run test:compile
# API integration tests against the local stack (from counter-cli/ directory)
cd counter-cli && yarn test-api
# Full validation (from root)
yarn validate
| Error | Cause | Fix |
|---|---|---|
compact: command not found | PATH not set | source $HOME/.local/bin/env |
ETARGET No matching version found | Version not in the tested set | Resolve current versions from the support matrix — see references/volatile.md. Do not install @latest. |
ECONNREFUSED 127.0.0.1:6300 | Proof server not running | Start proof server: docker compose -f proof-server.yml up |
WalletFacade.init is not a function | Old WalletFacade usage | Use WalletFacade.init() static factory, not new WalletFacade() |
MidnightBech32m.encode is not a function | Missing address-format import | Import from @midnightntwrk/wallet-sdk-address-format |
Failed to clone intent | Wallet SDK 1.x signing bug | Gone in Wallet SDK 2.x (signRecipe signs per stage); upgrade instead of patching |
| DUST = 0 after failed deploy | DUST coins locked | Restart the process — wallet.stop() then rerun |
| 0 balance after faucet | Wallet not synced yet | Wait for sync; check unshielded address was used |
Cannot find module | Contract not compiled or not built | cd contract && npm run compact && npm run build (the CLI imports dist/) |
prove: no SRS params for k=6 | Circuit too small for prover | Add dummy ledger fields to increase circuit size |
| Old address fails after recompile | Verifier key changed | Redeploy contract |
Copy templates/counter-dapp/ first and get it running unchanged. Then, to replace the counter with your own contract:
contract/src/counter.compact with your contractcd contract && npm run compact && npm run buildcontract/src/witnesses.ts with your private state typecontract/src/index.ts to export your contract symbolscounter-cli/src/common-types.ts — update type aliases for your circuitscounter-cli/src/api.ts:
counterCompiledContract with your contract referencecounterContractInstance, deploy, joinContract as neededincrement with your circuit callsCounter.ledger(contractState.data) with your ledger fieldprivateStateStoreName in config.ts (contractConfig) to avoid LevelDB collisionsconfigureProviders derives it from the wallet's coin public key, so anyone who knows that key can reproduce it. Ask the user for a password or derive it from secret wallet materialWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub kali-decoder/midnight-skills --plugin midnight-skills43 skills in this plugin
/1am-walletIntegrate the 1AM wallet for dust-free contract deployment and transaction flow on Midnight Network. Use this skill whenever a user is building a Midnight Network dApp, connecting to the 1AM browser extension, deploying or calling a Compact contract, handling ZK proving, setting up providers, or asking about dust-free transaction flow. Also use it for indexer patching, private state providers, payload encryption, or any question involving window.midnight['1am']./android-example-votingBuild a voting/poll dApp on Midnight Network using the Kuira Android SDK — Compact smart contract with create/cast/close circuits, passkey-derived identity, embedded wallet, Compose UI, reactive ledger reads via observeLedger(), and on-device ZK proving. Use when building a poll or voting dApp targeting Android./Other plugins' skills for the same job