Back to Browse

Use with your AI agent

  1. Install — run npx skills add Kali-Decoder/Midnight-skills --skill example-leaderboard-dapp for this skill, or npx skills add Kali-Decoder/Midnight-skills for all
  2. Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
  3. Build — the agent loads this skill and scaffolds your Midnight work

Example Leaderboard Dapp

Full-Fledged TemplatesAdvancedReviewedUpdated 10 days agov1.0.0

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 prompts

Build 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:

  1. Arcade leaderboard with privacy modes, `persistentHash` owner commitments, and `verifyOwnership` ZK proofs.
  2. 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 changes

No changes in v1.0.16 — last updated in v1.0.14.

On this page · 11 sections
SKILL.md

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 scripts
  • app/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 decode
  • lib/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 helpers
  • references/gotchas.md — Ledger 9 errors (version mismatch, EraMismatchError, Blockfrost 410/403), ZK asset paths
  • references/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/call
  • example-payment-dapp/ — provider wiring, indexer polling
  • compact/ — disclose(), witnesses, persistentHash, Map, Counter, assert
  • security/ — what is public on-chain vs private in witness data
  • indexer/ — read contract state without wallet connection

Key architecture notes:

  • scores is a public Map<Uint<64>, ScoreEntry> — readable from the indexer by anyone
  • localSecretKey witness returns a 32-byte secret from private state; never disclosed on-chain
  • ownerCommitment(sk) uses persistentHash with domain separator "leaderboard:owner:"
  • useCustomName boolean selects witness-fed name vs hash-based anonymous display name
  • verifyOwnership is a proof-only circuit — no ledger writes; use for "prove this is my score"
  • Persist secret key in localStorage so ownership proofs work after page refresh
  • Use deployContract / findDeployedContract with providers typed to the contract (templates/leaderboard-dapp/lib/leaderboard.ts)
  • Plain indexerPublicDataProvider(network.indexer); the old offset: null patch 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:

  1. Contract — leaderboard.compact compile + witnesses (localSecretKey, getCustomName)
  2. Providers — createConnectedSession (from references/midnight-session.md)
  3. Deploy — low-level deploy, persist private state + contract address
  4. Read state — indexer GraphQL → ContractState.deserialize → ledger() → decode entries
  5. Submit score — submitScore(score, useCustomName) with optional setCustomName beforehand
  6. Verify ownership — verifyOwnership(entryId) for prize claims or "yours" badges
  7. 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; verifyOwnership re-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:

FunctionPurpose
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:

  1. Connect — detectWallet() → wallet.connect('preprod') → createConnectedSession(api, ZK_PATH)
  2. Deploy / Join — deploy new contract or paste existing 64-char hex address
  3. Play — 10-second click challenge
  4. Submit — pick Anonymous / Public / Custom, then submitScore
  5. Leaderboard — auto-refresh from indexer every 15s (no wallet required to read)
  6. 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/leaderboard assets in build step (npm run sync:assets)
  • Store default contract address in env or localStorage for returning players
  • verifyOwnership does not mutate ledger — safe for repeated "prove mine" UX
  • Network and endpoints come from the wallet (dappConnectorNetwork). To target another network, change wallet.connect('preprod') in app/leaderboard/LeaderboardClient.tsx and set the wallet to match

9) Adapting This Template

templates/leaderboard-dapp/ is the source of truth; copy it rather than retyping files.

  1. Copy, run, then change. Get the unchanged template working first (Quick Commands below).
  2. Contract. Edit 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.
  3. Witnesses and private state. 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.
  4. Circuits and state. Wrappers are in 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.
  5. UI. app/leaderboard/LeaderboardClient.tsx holds the game and all wallet calls, including the target network in wallet.connect('preprod').
  6. Secrets. 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.
  7. Recompile and resync after every contract change (npm run compact && npm run sync:assets).
  8. 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.

Start in 2 steps

  1. 1. Install — one skill or the full set
  2. 2. Prompt — paste the example into your agent

Install all skills (recommended)

npx skills add Kali-Decoder/Midnight-skills

One command adds every Midnight skill to Cursor, Claude Code, and similar agents.

Install this skill only

npx skills add Kali-Decoder/Midnight-skills --skill example-leaderboard-dapp

Installs only "example-leaderboard-dapp" into every detected agent (Cursor, Claude Code, Codex, …).

Example agent prompt

Build 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.

Paste into Cursor, Claude Code, or Codex after installing.

Try runnable template
Author
Kali-Decoder
Category
Full-Fledged Templates
Difficulty
advanced
Version
v1.0.0

Tags

LeaderboardZK proofsArcade

Files included

SKILL.md
Create Social CardLive HackathonsGallery
Mock Demo
Example Leaderboard Dapp