/midnight-skills:example-leaderboard-dappfrom midnight-skills
Builds a privacy-preserving arcade leaderboard DApp on Midnight Network with ZK proofs, Next.js frontend, and 1AM wallet integration. Covers Compact contracts, deploy/call, indexer reads, and anonymous display names.
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.
A privacy-preserving leaderboard where players submit scores on-chain with three display modes and prove they own an entry using verifyOwnership — a ZK circuit that checks ownerCommitment(secretKey) matches the stored ownerHash without revealing the secret.
Runnable template: Copy templates/leaderboard-dapp/ for a complete Next.js project (contract + UI). Run npm install && npm run compact && npm run sync:assets && npm run dev after installing the 1AM wallet.
What this skill produces:
contract/ — Compact leaderboard + TypeScript witnesses + compile scriptsapp/leaderboard/ — Next.js client UI (click game, privacy mode picker, leaderboard table)lib/midnight.ts — wallet session + patched indexer provider (copy from references/midnight-session.md or templates/leaderboard-dapp/lib/midnight.ts)lib/leaderboard.ts — deploy, submitScore, verifyOwnership, ledger decodelib/display-name.ts — decode anonymous hash bytes to generated names ("Crimson Tiger")public/zk/leaderboard/ — ZK proving assets synced from contract buildShared references (canonical provider + troubleshooting — do not duplicate in prompts):
references/midnight-session.md — createConnectedSession, indexer patch, deploy/call helpersreferences/gotchas.md — Ledger 9 errors (version mismatch, EraMismatchError, Blockfrost 410/403), ZK asset pathsreferences/versions.json — the Ledger 9.1 pin set (@midnightntwrk/* + @midnight-ntwrk/compact-*)Primary references:
example-locker-dapp/ / templates/locker-dapp/ — Next.js + 1AM pattern, low-level deploy/callexample-payment-dapp/ — provider wiring, indexer pollingcompact/ — disclose(), witnesses, persistentHash, Map, Counter, assertsecurity/ — what is public on-chain vs private in witness dataindexer/ — read contract state without wallet connectionKey architecture notes:
scores is a public Map<Uint<64>, ScoreEntry> — readable from the indexer by anyonelocalSecretKey witness returns a 32-byte secret from private state; never disclosed on-chainownerCommitment(sk) uses persistentHash with domain separator "leaderboard:owner:"useCustomName boolean selects witness-fed name vs hash-based anonymous display nameverifyOwnership is a proof-only circuit — no ledger writes; use for "prove this is my score"localStorage so ownership proofs work after page refreshdeployContract / findDeployedContract with providers typed to the contract (templates/leaderboard-dapp/lib/leaderboard.ts)indexerPublicDataProvider(network.indexer); the old offset: null patch is obsolete on indexer 4.4.101When helping the user, follow this sequence:
leaderboard.compact compile + witnesses (localSecretKey, getCustomName)createConnectedSession (from references/midnight-session.md)ContractState.deserialize → ledger() → decode entriessubmitScore(score, useCustomName) with optional setCustomName beforehandverifyOwnership(entryId) for prize claims or "yours" badgesleaderboard-dapp/
├── package.json
├── next.config.mjs
├── lib/
│ ├── isomorphic-ws-fix.mjs
│ ├── midnight.ts # session, patched provider, hex helpers
│ ├── leaderboard.ts # deploy, submitScore, verifyOwnership, decode
│ └── display-name.ts # anonymous name generator
├── app/
│ ├── layout.tsx
│ └── leaderboard/
│ └── LeaderboardClient.tsx # game + wallet + leaderboard UI
├── contract/
│ ├── package.json
│ └── src/
│ ├── leaderboard.compact
│ ├── witnesses.ts
│ ├── index.ts
│ └── managed/leaderboard/ # compiler output (gitignored)
├── scripts/
│ └── sync-zk-assets.mjs # → public/zk/leaderboard/
└── public/zk/leaderboard/ # keys + zkir (gitignored until sync)
contract/src/leaderboard.compact:
struct ScoreEntry {
score: Uint<64>,
displayName: Bytes<32>,
ownerHash: Bytes<32>
}
export ledger scores: Map<Uint<64>, ScoreEntry>;
export ledger nextId: Counter;
witness localSecretKey(): Bytes<32>;
witness getCustomName(): Bytes<32>;
export circuit ownerCommitment(sk: Bytes<32>): Bytes<32> {
return persistentHash<Vector<2, Bytes<32>>>([pad(32, "leaderboard:owner:"), sk]);
}
export circuit submitScore(score: Uint<64>, useCustomName: Boolean): [] { /* ... */ }
export circuit verifyOwnership(targetEntryId: Uint<64>): [] { /* ... */ }
Privacy design:
useCustomName = false): displayName = persistentHash(sk) — UI decodes to generated nameuseCustomName = true): displayName = getCustomName() witness — app feeds address or user nameownerHash = ownerCommitment(sk) stored on every entry; verifyOwnership re-derives and comparesCompile:
cd contract && npm run compact && cd ..
npm run sync:assets
contract/src/witnesses.ts:
export type LeaderboardPrivateState = { secretKey: Uint8Array };
export const witnesses = {
localSecretKey: (ctx) => [ctx.privateState, ctx.privateState.secretKey] as const,
getCustomName: (ctx) => [ctx.privateState, customName] as const,
};
export const setCustomName = (name: string) => { /* encode to Bytes<32> */ };
Call setCustomName(name) in TypeScript before submitScore when using public or custom display modes.
lib/leaderboard.ts mirrors the locker-dapp pattern:
| Function | Purpose |
|---|---|
getOrCreateSecretKey() | Persist 32-byte secret in localStorage |
deployLeaderboard(session) | createUnprovenDeployTx + submitTxAsync |
submitScore(session, addr, score, customName?) | submitCallTxAsync → submitScore circuit |
verifyOwnership(session, addr, entryId) | submitCallTxAsync → verifyOwnership circuit |
fetchLeaderboardState(queryUrl, addr) | Indexer poll + decodeLeaderboardState |
ZK asset path: /zk/leaderboard (synced to public/zk/leaderboard/).
LeaderboardClient.tsx flow:
detectWallet() → wallet.connect('preprod') → createConnectedSession(api, ZK_PATH)submitScoreverifyOwnership(entryId) marks entry as yours in UIIndexer-only reads mean spectators can watch the leaderboard without connecting a wallet.
Versions: the Ledger 9.1 set in references/versions.json: Compact toolchain and language, compact-runtime, ledger-v9, Midnight.js, DApp Connector API, and the proof server image (only needed if your wallet proves locally). Resolve the current set with references/volatile.md before pinning.
compact update 0.36.1
docker run -d -p 6300:6300 midnightntwrk/proof-server:9.0.2 midnight-proof-server -v # optional
Wallet: a Ledger 9 build of 1AM (or Lace) on Preview or Preprod, with tNIGHT from the faucet registered for DUST (re-register on Preprod after 9 Nov 2026; Preview relaunched on 7 Nov 2026). Template status (21 Nov 2026): contract compiles with 0.36.1, and the app type-checks and passes next build.
Pin versions from references/versions.json. Cross-check docs.midnight.network support matrix before upgrading.
public/zk/leaderboard assets in build step (npm run sync:assets)localStorage for returning playersverifyOwnership does not mutate ledger — safe for repeated "prove mine" UXdappConnectorNetwork). To target another network, change wallet.connect('preprod') in app/leaderboard/LeaderboardClient.tsx and set the wallet to matchtemplates/leaderboard-dapp/ is the source of truth; copy it rather than retyping files.
contract/src/leaderboard.compact. If you rename it, update the compact script in contract/package.json, the managed/<name> imports and zkConfigPath in contract/src/index.ts, ZK_PATH in lib/leaderboard.ts, and the folder in scripts/sync-zk-assets.mjs.contract/src/witnesses.ts defines localSecretKey (reads secretKey from LeaderboardPrivateState) and getCustomName (returns the name last passed to setCustomName, kept in a module variable, not private state). Change them together with the contract's witness declarations.lib/leaderboard.ts (deployLeaderboard, submitScore, verifyOwnership, fetchLeaderboardState). Rename or add callTx.<circuit> calls there; decodeDisplayName in lib/display-name.ts turns stored name bytes back into text.app/leaderboard/LeaderboardClient.tsx holds the game and all wallet calls, including the target network in wallet.connect('preprod').getOrCreateSecretKey and demoStoragePassword (in lib/midnight.ts) keep keys in localStorage. That is demo-grade; for production, derive them from wallet-held material or let the user back them up.npm run compact && npm run sync:assets).references/versions.json.git clone --depth 1 --filter=blob:none --sparse https://github.com/Kali-Decoder/Midnight-Skills.git
cd Midnight-Skills && git sparse-checkout set templates/leaderboard-dapp
cp -R templates/leaderboard-dapp ../my-leaderboard && cd ../my-leaderboard
npm install
npm run compact
npm run sync:assets
npm run dev
Open http://localhost:3000 → Connect 1AM → Deploy New → play → submit → refresh leaderboard.
What 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