The fastest way to build Midnight smart contracts with automated CLI generation.
Create a new Midnight smart contract project in seconds with zero configuration. This scaffold provides everything you need to build, test, and deploy smart contracts on the Midnight blockchain with enhanced data type support and professional tooling. The scaffold comes with pre-generated wallet.
π From contract to production in minutes, not hours.
"It feels almost like magic :)"
β Midnight developers oncreate-midnight-app
- π Zero Configuration - Just create a
.compact
file and everything auto-generates - π Auto-generating CLI that adapts to your contract functions with intelligent parameter detection
- π Seamless testnet deployment with automated wallet management and balance checking
- π° Built-in wallet tools for balance checking, faucet requests, and transaction management
- π Smart contract analysis with automatic type generation and parameter detection
- π Comprehensive documentation with built-in debugging guides and troubleshooting
- π― Enhanced Data Type Support - Full support for all Midnight contract types including complex parameters
- π οΈ Professional Tooling with error handling, validation, dry-run support, and clear feedback
- π Witness Function Support - Automatically detects and includes private state functions
Get started with Midnight development in under 2 minutes: make sure you are using the latest version
# Create a new project
npx create-midnight-app@latest my-contract
# Navigate to project
cd my-contract
# Set up your wallet environment
mv .env.example .env
# Create your smart contract
touch voting.compact
# deploy to testnet & start interacting
npm run deploy
β
That is ALL!
β οΈ Make sure you are using Node 20 β this is important!
π Write Your First Contract:
Edit your contract file:
pragma language_version 0.15;
import CompactStandardLibrary;
export ledger votes: Counter;
export circuit vote(): [] {
votes.increment(1);
}
export circuit get_votes(): Uint<64> {
return votes;
}
π― Deploy in an instant
# Auto-generate CLI, compile & deploy contract and start interacting
npm run deploy
This single command:
- π Syncs your contract to the build system
- π¨ Compiles contract and generates ZK keys
- π Creates TypeScript types and API functions
- π₯οΈ Builds a dynamic CLI that adapts to your contract
- β Everything ready to use!
π Deploy & Test:
# For testnet wallet generation
npm run wallet - # the generated wallet will automatically be saved into .env
# For requesting token from faucet
npm run faucet
# For testnet deployment
npm run deploy
Command | Description | Environment |
---|---|---|
npm run dev |
π Main development command - syncs, compiles, generates CLI | Local |
npm run deploy |
π Deploy to Midnight testnet | Testnet |
npm run wallet |
π generate a new key-pair wallet on Midnight | Testnet |
npm run balance |
π° Check current testnet wallet balance | Testnet |
npm run faucet |
π° Request testnet tokens | Testnet |
npm run check |
β Verify scaffold is ready and show status | Local |
npm run build |
π¨ Build all workspaces | Local |
npm run deploy:new |
π¨ Deploy to Midnight testnet(default) | Testnet |
npm run deploy:join |
π¨ Auto-join existing contract | Testnet |
npm run docs |
π Open the official Compact documentation |
Flag | Behavior | Use Case |
---|---|---|
--dry-run |
Preview commands only | Testing scripts |
--help |
Show detailed help | Documentation |
-
Create Contract - Write your
.compact
file in the project root -
Auto-Generate - Run
npm run dev
to generate everything automatically -
Deploy & Test - Use
npm run deploy
for testnet deployment &npm run wallet
a new wallet generation -
Iterate - Edit contract, run
npm run dev/deploy
, repeat
-
π Edit: Modify your
.compact
contract in the project root -
π Sync:
npm run dev
copies it to build directory - π¨ Compile: Contract compiles with ZK keys generation
- π Generate: TypeScript types and API functions auto-generated
- π₯οΈ Build: CLI updates with new contract functions
- β Ready: Everything synchronized and ready to use
-
Auto-Detection: Automatically finds and analyzes your
.compact
contracts - Smart Contract Analysis: Works with any contract structure and function names
- Zero Manual Updates: Change functions β regenerate β everything adapts automatically
- Witness Function Support: Automatically detects and includes private state functions
-
One-Command Testnet Deployment:
npm run deploy
for full testnet development setup - Docker Integration: Automatically manages local Midnight node containers
- Testnet Deployment: Seamless testnet integration with automated wallet management
-
Dry Run Support: Preview deployment with
--dry-run
flag
- Root-Level Editing: Edit contracts directly in project root for easy access
- Auto-Sync Pipeline: Automatically syncs contracts to build directories
- Clean Builds: Removes old artifacts before rebuilding
- Hot Reload: Instant updates when contract changes
- Enhanced Data Type Support: Full support for complex Midnight contract types
- Automatic Wallet Generation: Creates secure wallets with one command
-
Balance Checking: Real-time testnet balance monitoring with
npm run balance
-
Faucet Integration: Automated and manual token requesting with
npm run faucet
- Transaction Management: Full transaction lifecycle support
my-project/
βββ my-contract.compact β π Your smart contract (edit here!)
βββ package.json β π¦ Main project configuration
βββ .env β π Wallet configuration (auto-generated)
βββ README.md β π Project documentation
βββ boilerplate/ β ποΈ Auto-generated tooling
βββ contract/ β π¨ Contract compilation workspace
β βββ src/ β π Auto-synced contracts & witnesses
β βββ my-contract.compact β Synced from root
β βββ witnesses.ts β π Private state functions
β βββ managed/ β ποΈ Compiled output & ZK keys
βββ contract-cli/ β π₯οΈ Generated CLI application
β βββ src/ β π― Dynamic CLI code
β β βββ api.ts β π Contract interaction API with enhanced data type support
β β βββ cli.ts β π₯οΈ Interactive CLI interface
β β βββ enhanced-api.ts β π Contract metadata & analysis
β βββ standalone.yml β π³ Docker configuration for local node
βββ scripts/ β βοΈ Build & deployment automation
βββ auto-generator.js β π Core auto-generation engine
βββ deploy.js β π Deployment orchestrator
βββ check-balance.js β π° Wallet balance checker
βββ request-faucet.js β π° Testnet token requests
The scaffold uses source-driven development:
-
Contract Analysis - Parses your
.compact
file to find all functions - Dynamic Generation - Creates TypeScript APIs for each function
- CLI Creation - Builds interactive menus for contract interaction
- Testnet Integration - Provides wallet and deployment tools
pragma language_version 0.15;
import CompactStandardLibrary;
export ledger count: Counter;
export circuit increment(value: Uint<16>): [] {
count.increment(value);
}
export circuit decrement(value: Uint<16>): [] {
count.decrement(value);
}
export circuit get_count(): Uint<64> {
return count;
}
pragma language_version 0.15;
import CompactStandardLibrary;
export ledger votes_for: Counter;
export ledger votes_against: Counter;
export circuit vote_yes(): [] {
votes_for.increment(1);
}
export circuit vote_no(): [] {
votes_against.increment(1);
}
export circuit get_results(): [Uint<64>, Uint<64>] {
return [votes_for, votes_against];
}
The system automatically:
-
Scans the root directory for
.compact
files - Copies them to the contract source directory (replacing old ones)
- Analyzes contract functions and ledger state
- Generates TypeScript types and API functions with enhanced data type support
- Builds a dynamic CLI that adapts to your contract
// Automatically detected from your contract:
export circuit increment(value: Uint<16>): [] { ... }
export circuit post(message: Opaque<"string">): [] { ... }
export circuit get_count(): Uint<64> { ... }
// Becomes CLI options with intelligent parameter handling:
// 1. Increment (numeric parameter with validation)
// 2. Post (string parameter with opaque type conversion)
// 3. Get Count (read-only function)
- Parameter Detection: Automatically detects function parameters and types
- Enhanced Data Type Support: Handles complex Midnight types including opaque strings
- Type Safety: Generates TypeScript interfaces with full type checking
- Read-Only Functions: Identifies and marks query functions
- Interactive Menus: Creates numbered options for all functions
- Input Validation: Validates parameters before contract calls
System Requirements:
- Node.js 20 (It must be 20!)
- NPM
-
Midnight Development Tools - Install
compactc
compiler - Docker Desktop (for local development)
# Check system requirements
node --version && docker --version && git --version
# Install Midnight compiler (if not installed)
# Follow Midnight documentation for compactc installation
Issue | Symptoms | Solution |
---|---|---|
Contract not detected | "No .compact files found" | Ensure .compact file is in project root |
Docker issues | Local deployment fails | Ensure Docker Desktop is running |
Testnet connection | Wallet sync timeouts | Check internet connection, try npm run balance
|
Zero balance | Deployment fails with "insufficient funds" | Run npm run faucet or use manual faucet |
Permission errors | File system access denied | Run with appropriate permissions or check file ownership |
# Verify contract syntax
npm run build
# Check wallet status
npm run balance
# View detailed logs
npm run deploy --dry-run
# Test local environment
docker ps
Create a .env
file for configuration:
# Wallet Configuration
WALLET_SEED=your-64-character-hex-seed-phrase
WALLET_ADDRESS=your-wallet-address
Option 1: Auto-generate wallet (Recommended)
npm run wallet
Option 2: Manual setup
# Copy example configuration
cp .env.example .env
# Edit .env file and add your seed
WALLET_SEED=your-64-character-hex-seed-phrase-here
# Check wallet balance
npm run balance
# Request testnet tokens
npm run faucet
Root .compact β Sync to src/ β Compile Contract β Generate ZK Keys β
Update TypeScript β Build CLI β Ready to Use!
- Contract Analyzer: Parses contract functions and types with enhanced data type support
- Dynamic Generator: Creates CLI menus and handlers for all parameter types
- API Layer: Handles contract interactions with type conversion
- Wallet Integration: Manages testnet connections and balance checking
We welcome contributions! Here's how to get started:
Types of contributions welcome:
- π Bug fixes - Fix issues with the scaffold or data type handling
- β¨ New features - Add functionality to improve developer experience
- π Documentation - Improve guides, examples, and API docs
- π¨ UI/UX - Enhance CLI interface and user experience
- π§ͺ Tests - Add test coverage and improve reliability
- π§ Data Type Support - Improve handling of complex Midnight types
Feature | Status | Notes |
---|---|---|
β Auto-CLI Generation | Complete | Supports all contract types |
β Enhanced Data Type Support | Complete | Full support for complex Midnight types |
β Local Development | Complete | Docker-based Midnight node |
β Testnet Deployment | Complete | Automated wallet management |
β Deployment Flags | Complete | Dry-run, auto-deploy options |
β Wallet Tools | Complete | Balance checking, faucet integration |
β Documentation | Complete | Comprehensive guides and troubleshooting |
π Multi-Contract Support | Planned | Support multiple contracts per project |
π GUI Interface | Planned | Web-based contract interaction |
π Contract Templates | Planned | Pre-built contract examples |
π Midnight Playground | Planned | Online midnight experimenting tool |
Apache 2.0 License
Before: Hours of manual setup, hardcoded configurations, manual CLI updates, type conversion issues After: Create contract β run command β deploy to testnet with full data type support
This scaffold eliminates all the friction from Midnight smart contract development, handles complex data types automatically, and gets you building immediately.
Last Updated: June 15, 2025
Version: 2.1.7
Built with β€οΈ for the Midnight ecosystem π
Happy coding on Midnight! πβ¨