Use with your AI agent
- Install — run
npx skills add Kali-Decoder/Midnight-skills --skill example-leaderboard-dappfor this skill, ornpx skills add Kali-Decoder/Midnight-skillsfor all - Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
- Build — the agent loads this skill and scaffolds your Midnight work
Example Leaderboard Dapp
Agent picks this when: Build a privacy-preserving leaderboard DApp on Midnight
Privacy-preserving arcade leaderboard: submit scores with anonymous/public/custom names and prove ownership via ZK.
Good for
- Arcade leaderboard with privacy modes, `persistentHash` owner commitments, and `verifyOwnership` ZK proofs.
- Next.js + 1AM wallet template with indexer reads and low-level deploy/call.
Preview in agent
Suggested promptsBuild a privacy-preserving leaderboard DApp on Midnight. Use the "example-leaderboard-dapp" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Prefer the runnable leaderboard-dapp template when scaffolding the app. Target Midnight Preprod unless I specify otherwise.
Loaded skill example-leaderboard-dapp
What the skill guides the agent to do:
- Arcade leaderboard with privacy modes, `persistentHash` owner commitments, and `verifyOwnership` ZK proofs.
- Next.js + 1AM wallet template with indexer reads and low-level deploy/call.
Illustrative — based on the skill's description, not recorded agent output.
Try it without installing: npx skills use Kali-Decoder/Midnight-skills@example-leaderboard-dapp
What changed in v1.0.16
All registry changesNo changes in v1.0.16 — last updated in v1.0.14.
On this page · 11 sections
Midnight Network Leaderboard DApp
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 fromreferences/midnight-session.mdortemplates/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 build
Shared 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 connection
Key architecture notes:
scoresis a publicMap<Uint<64>, ScoreEntry>— readable from the indexer by anyonelocalSecretKeywitness returns a 32-byte secret from private state; never disclosed on-chainownerCommitment(sk)usespersistentHashwith domain separator"leaderboard:owner:"useCustomNameboolean selects witness-fed name vs hash-based anonymous display nameverifyOwnershipis a proof-only circuit — no ledger writes; use for "prove this is my score"- Persist secret key in
localStorageso ownership proofs work after page refresh - Use
deployContract/findDeployedContractwith providers typed to the contract (templates/leaderboard-dapp/lib/leaderboard.ts) - Plain
indexerPublicDataProvider(network.indexer); the oldoffset: nullpatch is obsolete on indexer 4.4.101 - The template reads the table through the connected wallet's indexer: preprod/mainnet indexers are now Blockfrost (token required), so a no-wallet read needs your own backend proxy or a Preview-only build
Workflow
When helping the user, follow this sequence:
- Contract —
leaderboard.compactcompile + witnesses (localSecretKey,getCustomName) - Providers —
createConnectedSession(fromreferences/midnight-session.md) - Deploy — low-level deploy, persist private state + contract address
- Read state — indexer GraphQL →
ContractState.deserialize→ledger()→ decode entries - Submit score —
submitScore(score, useCustomName)with optionalsetCustomNamebeforehand - Verify ownership —
verifyOwnership(entryId)for prize claims or "yours" badges - UI — click game, privacy mode selector, leaderboard table with prove button
1) Project Structure
leaderboard-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)
2) Compact Contract
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:
- Anonymous mode (
useCustomName = false):displayName = persistentHash(sk)— UI decodes to generated name - Public / Custom mode (
useCustomName = true):displayName = getCustomName()witness — app feeds address or user name - Ownership:
ownerHash = ownerCommitment(sk)stored on every entry;verifyOwnershipre-derives and compares
Compile:
cd contract && npm run compact && cd ..
npm run sync:assets
3) Witnesses
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.
4) TypeScript Integration
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/).
5) Browser UI
LeaderboardClient.tsx flow:
- Connect —
detectWallet()→wallet.connect('preprod')→createConnectedSession(api, ZK_PATH) - Deploy / Join — deploy new contract or paste existing 64-char hex address
- Play — 10-second click challenge
- Submit — pick Anonymous / Public / Custom, then
submitScore - Leaderboard — auto-refresh from indexer every 15s (no wallet required to read)
- Prove —
verifyOwnership(entryId)marks entry as yours in UI
Indexer-only reads mean spectators can watch the leaderboard without connecting a wallet.
6) Prerequisites
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.
7) Compatibility Matrix
Pin versions from references/versions.json. Cross-check docs.midnight.network support matrix before upgrading.
8) Production Notes
- Deploy frontend to Vercel/Netlify; set
public/zk/leaderboardassets in build step (npm run sync:assets) - Store default contract address in env or
localStoragefor returning players verifyOwnershipdoes not mutate ledger — safe for repeated "prove mine" UX- Network and endpoints come from the wallet (
dappConnectorNetwork). To target another network, changewallet.connect('preprod')inapp/leaderboard/LeaderboardClient.tsxand set the wallet to match
9) Adapting This Template
templates/leaderboard-dapp/ is the source of truth; copy it rather than retyping files.
- Copy, run, then change. Get the unchanged template working first (Quick Commands below).
- Contract. Edit
contract/src/leaderboard.compact. If you rename it, update thecompactscript incontract/package.json, themanaged/<name>imports andzkConfigPathincontract/src/index.ts,ZK_PATHinlib/leaderboard.ts, and the folder inscripts/sync-zk-assets.mjs. - Witnesses and private state.
contract/src/witnesses.tsdefineslocalSecretKey(readssecretKeyfromLeaderboardPrivateState) andgetCustomName(returns the name last passed tosetCustomName, kept in a module variable, not private state). Change them together with the contract'switnessdeclarations. - Circuits and state. Wrappers are in
lib/leaderboard.ts(deployLeaderboard,submitScore,verifyOwnership,fetchLeaderboardState). Rename or addcallTx.<circuit>calls there;decodeDisplayNameinlib/display-name.tsturns stored name bytes back into text. - UI.
app/leaderboard/LeaderboardClient.tsxholds the game and all wallet calls, including the target network inwallet.connect('preprod'). - Secrets.
getOrCreateSecretKeyanddemoStoragePassword(inlib/midnight.ts) keep keys inlocalStorage. That is demo-grade; for production, derive them from wallet-held material or let the user back them up. - Recompile and resync after every contract change (
npm run compact && npm run sync:assets). - Versions. Add dependencies only at the versions in
references/versions.json.
Quick Commands
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.
Related skills
Example Passport Dapp
Runnable Midnight Passport foundations demo — passkey onboarding, custody deploy, Night ID, deposit, localnet via npm run demo.
Android Example Voting
Build 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.
Example Counter
Complete Midnight DApp reference — headless wallet, CLI, counter contract, DUST generation, deploy, interaction.
Example Hello World
Build a complete Midnight Network hello-world DApp from scratch with Compact, vitest, and FluentWalletBuilder.