For the complete documentation index, see llms.txt
Leaderboard tutorial
Prerequisites: work through the ZK Loan tutorial first. This tutorial assumes you can compile a contract, write a witness, and read a Midnight.js test suite.
Every example so far has run from a test suite. This one ends as a website. You take a small Compact contract, wrap it in a TypeScript API that both a browser and Node can use, build a React DApp that talks to the Lace wallet, and deploy it to Vercel as a static site.
The contract is an arcade-style leaderboard. Players submit scores, under a name they choose or anonymously, and every submission becomes a new public entry. Each entry also stores a commitment to the player's secret key, so a player can later prove with a zero-knowledge proof that an entry is theirs, without revealing the key.
The source for this tutorial is
examples/leaderboard
in midnight-examples. Its SPEC.md
is the design card, including what the leaderboard makes public.
Set up
Clone midnight-examples, install the workspace, and compile every contract:
git clone https://github.com/midnightntwrk/midnight-examples.git
cd midnight-examples
npm install && npm run compile
Then move into the example:
cd examples/leaderboard
Overview
Architecture, prerequisites, wallet setup, and how the example is laid out.
Smart contract
Structured on-chain data with Map, Counter, and a struct; witnesses that supply private data on demand; ownership proofs.
TypeScript integration
Witnesses, contract exports, and a shared API class that deploys and calls the contract from the browser or Node.
Browser DApp
A React frontend that connects to Lace, reads state from the indexer, and submits scores on-chain.
Production deployment
Deploy the DApp to Vercel as a static site, with the compiled circuit keys served alongside it.