The definitive guide to learning Compact, Midnight's zero-knowledge smart contract language
This project extends the Midnight Network with additional developer tooling.
Learn Compact is an interactive book and exercise collection for learning the Compact programming language. Compact is the smart contract language for Midnight, a blockchain with native support for zero-knowledge proofs.
This project is inspired by:
Developers with programming experience who want to:
- Build privacy-preserving smart contracts
- Learn zero-knowledge proof concepts
- Develop on the Midnight blockchain
Prerequisites:
- Programming experience in any language
- TypeScript/JavaScript knowledge (helpful but not required)
- Basic blockchain concepts (we'll cover what you need)
git clone https://github.com/Olanetsoft/learn-compact.git
cd learn-compactchmod +x scripts/setup.sh
./scripts/setup.sh# Install mdBook if you haven't
cargo install mdbook
# Serve the book locally
cd book
mdbook serveOpen http://localhost:3000 in your browser.
cd exercises/01_basics/01_hello_compact
# Read README.md
# Edit exercise.compact
# Compile to check your solution
compact compile exercise.compactlearn-compact/
├── book/ # mdBook source (the textbook)
│ └── src/
│ ├── ch00-introduction.md
│ ├── ch01-getting-started/
│ ├── ch02-basic-concepts/
│ └── ...
├── exercises/ # Hands-on exercises (rustlings-style)
│ ├── 01_basics/
│ ├── 02_types/
│ ├── 03_circuits/
│ └── solutions/
├── examples/ # Complete working contracts
│ ├── counter/
│ ├── bulletin-board/
│ └── voting/
└── scripts/ # Helper scripts
- Read the corresponding chapter in the book
- Open the exercise folder
- Read the exercise README.md
- Edit exercise.compact to complete the TODOs
- Compile with
compact compile exercise.compact - Fix any errors
- Move to the next exercise
Check your progress:
./scripts/verify.sh| Part | Topics | Exercises |
|---|---|---|
| 1. Foundations | Intro, Setup, Basics | 01_basics |
| 2. Type System | Primitives, Compounds, User-defined | 02_types |
| 3. Core Features | Circuits, Witnesses, Control Flow | 03_circuits, 04_witnesses |
| 4. State Management | Ledger, Counter, Map, Set | 05_ledger |
| 5. Advanced | Stdlib, Modules, TypeScript | 06_patterns |
| 6. Projects | Counter, Bulletin Board, Voting | examples/ |
| Wrong | Correct |
|---|---|
ledger { field: Type } |
export ledger field: Type; |
circuit fn(): Void |
circuit fn(): [] |
Choice::rock |
Choice.rock |
witness fn(): T { } |
witness fn(): T; |
See Chapter 19: Common Mistakes for the full list.
- Compact Language: v0.16+
- Compiler: compact v0.5.1 (compiler 0.30.0, runtime 0.15.0)
- Last Updated: April 2026
Contributions welcome! Please:
- Ensure all Compact code compiles
- Each exercise tests ONE concept
- Follow the progressive difficulty structure
MIT License - See LICENSE for details.
- Midnight Official Docs
- Compact Language Reference
- Midnight Discord
- Local Development Network - Run your own local Midnight node (community tool by Brick Towers)
Happy Learning! 🚀