Skip to content

Olanetsoft/learn-compact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learn Compact 🌙

The definitive guide to learning Compact, Midnight's zero-knowledge smart contract language

CI License: MIT

This project extends the Midnight Network with additional developer tooling.

📖 What is This?

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:

🎯 Who is This For?

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)

🚀 Getting Started

1. Clone the Repository

git clone https://github.com/Olanetsoft/learn-compact.git
cd learn-compact

2. Run Setup Script

chmod +x scripts/setup.sh
./scripts/setup.sh

3. Read the Book

# Install mdBook if you haven't
cargo install mdbook

# Serve the book locally
cd book
mdbook serve

Open http://localhost:3000 in your browser.

4. Do the Exercises

cd exercises/01_basics/01_hello_compact
# Read README.md
# Edit exercise.compact
# Compile to check your solution
compact compile exercise.compact

📚 Structure

learn-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

📝 Exercise Workflow

  1. Read the corresponding chapter in the book
  2. Open the exercise folder
  3. Read the exercise README.md
  4. Edit exercise.compact to complete the TODOs
  5. Compile with compact compile exercise.compact
  6. Fix any errors
  7. Move to the next exercise

Check your progress:

./scripts/verify.sh

🎓 Learning Path

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/

⚠️ Common Mistakes

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.

🔧 Version Compatibility

  • Compact Language: v0.16+
  • Compiler: compact v0.5.1 (compiler 0.30.0, runtime 0.15.0)
  • Last Updated: April 2026

🤝 Contributing

Contributions welcome! Please:

  1. Ensure all Compact code compiles
  2. Each exercise tests ONE concept
  3. Follow the progressive difficulty structure

📜 License

MIT License - See LICENSE for details.

🔗 Resources


Happy Learning! 🚀

About

Learn Compact programming language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors