Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Setting Up the Compiler

This note walks through installing the Compact toolchain and getting your first contract compiled.

Goal after this note: Have compact installed and able to compile a basic contract.


Intuition First

Compact has two tools:

  • compact, The CLI you use day-to-day (compile, format, fixup).
  • compactc, The actual compiler. You invoke it via compact compile.

The toolchain has one non-obvious dependency: Docker. The proof server generates ZK proofs locally and requires Docker Desktop running. This is the step most people skip.


The Three Components

ComponentWhat it isRuns where
compact CLIYour interface to the toolchainYour terminal
compact compileThe actual compilerInvoked by compact
Proof server (Docker)Generates ZK proofs locallyDocker Desktop

You interact with the CLI. The CLI invokes the compiler. The proof server generates proofs when you call circuits.


Prerequisites

Before installing Compact, ensure you have:

  • Docker Desktop, Required for the proof server
  • Chrome browser, For the Lace Wallet extension
  • Visual Studio Code, For the syntax extension
  • Lace Wallet (Chrome extension), For wallet integration during development

Note: Linux and macOS are directly supported. On Windows, use WSL.


Step 1: Install the compact CLI

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | sh

Add the binary to your PATH:

export PATH="$HOME/.compact/bin:$PATH"

Where it installs: The installer places compact at $HOME/.compact/bin/compact. Add this directory to your PATH permanently (in .bashrc or equivalent).

Verify:

compact --version

Step 2: Install the Compiler

compact update

This downloads and installs the current compiler version.

Verify both:

compact --version
compact compile --version

Step 3: Start the Proof Server

The proof server generates ZK proofs locally. It requires Docker Desktop running.

docker run -p 6300:6300 midnightntwrk/proof-server:8.0.3 midnight-proof-server -v

What this does:

  • Starts the proof server container on port 6300
  • The server listens at http://localhost:6300

Configure Lace Wallet to use it:

  1. Open Lace Wallet
  2. Go to Settings → Midnight
  3. Select Local (http://localhost:6300)

Tip: Keep Docker Desktop running whenever you’re developing. The proof server must be up when you call circuits.


Step 4: Install the VS Code Extension

  1. Download the VSIX package:
    https://raw.githubusercontent.com/midnight-ntwrk/releases/gh-pages/artifacts/vscode-extension/compact-0.2.13/compact-0.2.13.vsix
    
  2. In VS Code: Extensions → Install from VSIX → select the downloaded file

This adds syntax highlighting for .compact files.


Compiling a Contract

With everything installed, compile your first contract:

compact compile contracts/counter.compact contracts/managed/counter

Output directory:

contracts/managed/counter/
├── contract/             # TypeScript runtime
│   ├── index.js
│   ├── index.d.ts
│   └── index.js.map
├── compiler/             # Metadata
│   └── contract-info.json
├── zkir/                 # ZK circuits
│   ├── *.zkir
│   └── *.bzkir
└── keys/                 # Proving keys
    ├── *.prover
    └── *.verifier

Development shortcut: Skip ZK key generation during development, it’s slow:

compact compile --skip-zk contracts/counter.compact contracts/managed/counter

Re-enable for production builds.


Other Commands

compact format contracts/           # format all .compact files
compact format --check contracts/    # check formatting (CI)
compact fixup contracts/            # apply source-level fixups
compact list --installed      # list installed versions

Troubleshooting

ErrorFix
compact: command not foundAdd $HOME/.compact/bin to PATH
Docker connection errorsEnsure Docker Desktop is running
Port 6300 in useUse a different port: -p 6301:6300
compact update failsCheck your internet connection; try again

Standard Library

The standard library is built into the compiler, it’s not a file on disk. Import it at the top of every contract:

import CompactStandardLibrary;

This gives you Maybe, Either, hashing functions, token operations, and more.


Quick Recap

  • compact is the CLI. compact compile invokes the compiler.
  • Install via the shell script. Add $HOME/.compact/bin to your PATH.
  • Docker Desktop must be running for the proof server.
  • Start the proof server: docker run -p 6300:6300 midnightntwrk/proof-server:8.0.3 midnight-proof-server -v
  • Use --skip-zk during development to skip slow key generation.
  • Import CompactStandardLibrary at the top of every contract.