midnight-deploy is a powerful and intuitive Command-Line Interface (CLI) tool designed to make compiling, deploying, and initializing your Midnight smart contracts effortless. Stop wrestling with complex scripts, obscure errors, and manual wallet management. With midnight-deploy, you declare what you want, and it handles the rest with a single, slick command.
Deploying smart contracts, especially on a cutting-edge ZK-proof blockchain like Midnight, is notoriously complex:
- Cryptic Errors: From WASM initialization to
LedgerParametersandERR_PACKAGE_PATH_NOT_EXPORTED, the path is fraught with obscure technical hurdles. - Boilerplate Hell: Manually configuring providers, handling wallet syncing, deriving keys, and orchestrating two-step deploy-then-initialize sequences.
- Slow Iteration: Each deployment attempt requires tedious manual steps, slowing down development.
- Hidden Complexity: While powerful, the underlying Midnight.js APIs are often low-level, demanding deep understanding just to get started.
This friction discourages new developers and slows down seasoned builders.
midnight-deploy abstracts away this complexity, providing a declarative, fast, and delightful developer experience (DX). It's built for rapid iteration in development and robust execution in production.
Imagine deploying your contract with just one line of configuration and one command. That's midnight-deploy.
- Declarative Configuration: Define your contracts, network, and initialization arguments in a simple
midnight.config.tsfile. - Zero-Boilerplate Deployment: Automates the entire complex process: contract compilation, wallet setup, network syncing,
deployContractcalls, and two-step initialization. - Slick UI Feedback: Enjoy beautiful, real-time status updates with spinners and colored logs, making the deployment process clear and confidence-inspiring.
- Quick Deploy Mode: Instantly generate a random deployer wallet and keys for rapid testing without touching
.envfiles. - Idempotent: Designed to be safely re-run. Future features will include caching and smart re-deployments.
- Type-Safe Configuration: Leverage TypeScript for your config files, with full autocomplete and validation.
- Full Midnight Stack Integration: Seamlessly uses
compactc,@midnight-ntwrk/wallet,@midnight-ntwrk/midnight-js-contracts,@noble/curves,bip39, and more.
This guide gets you from zero to a deployed Midnight smart contract in minutes.
- Node.js v22+: Ensure you have the latest Node.js LTS installed (recommended via
nvm). compactcCompiler: Install the Midnightcompactccompiler and ensure its absolute path is used inmidnight-deploy's scripts (see Installation).- Docker: Required for running the local Midnight Proof Server.
- Lace - Midnight Preview Wallet: Install this Chrome/Brave extension if you plan to import a deployer mnemonic and fund it.
- Clone this repository:
git clone https://github.com/hitakshiA/midnight-deploy cd midnight-deploy - Install dependencies:
npm install
This mode is perfect for rapid development and testing. It generates a random deployer wallet and keys on the fly.
-
Start your Midnight Proof Server (in a separate terminal):
docker run -p 6300:6300 midnightnetwork/proof-server -- 'midnight-proof-server --network testnet' -
Run the deployment:
npm start -- deploy --config ./example/midnight.config.ts --quick-deploy
(The
--is important to passdeployand--configto our script).Watch the beautiful console output! Your contract will compile, deploy, and initialize with zero manual setup.
For persistent deployments or to use a specific funded wallet (e.g., in Lace), you'll provide your own deployer seed.
-
Generate a new 24-word Mnemonic:
npm start -- generate-wallet
This will print a
DEPLOYER_MNEMONIC="..."line. -
Create/Update
example/.env:- Create a file
example/.envin yourmidnight-deploy/exampledirectory. - Paste the
DEPLOYER_MNEMONIC="..."line (and anyADMIN_PUBLIC_KEYif needed for your contract'sinitArgs) into it.
- Create a file
-
Import & Fund Wallet:
- Import this 24-word mnemonic phrase into a new Lace - Midnight Preview Wallet account.
- Go to the Midnight Faucet and send
tDUSTto your new wallet's address.
-
Run the deployment:
npm start -- deploy --config ./example/midnight.config.ts
The tool will detect your funded wallet, wait for sync, and proceed with deployment.
Your deployment is defined in midnight.config.ts (e.g., example/midnight.config.ts).
// example/midnight.config.ts
/** @type {import('midnight-deploy').DeployConfig} */
export default {
// Your deployer wallet's mnemonic (read from .env or provided via --seed)
deployerMnemonic: process.env.DEPLOYER_MNEMONIC,
// A list of contracts to deploy in sequence
contracts: [
{
name: 'PassportContract', // A friendly name for reporting
path: './contracts/Passport.compact', // Path to your Compact source file
// Optional: Initialization arguments for a circuit to call post-deployment
init: (keys) => ({
circuit: 'initialize', // The circuit name to call
args: {
initialAdminPk: keys.publicKey, // Arguments, `keys` is provided by the deployer
},
}),
},
// You can add more contracts here, they will deploy in order!
// {
// name: 'AnotherContract',
// path: './contracts/Another.compact',
// init: (keys) => ({ circuit: 'setup', args: { owner: keys.publicKey } })
// }
],
};$ npm start -- deploy --config ./example/midnight.config.ts --quick-deploy
β Configuration loaded
β Compiled PassportContract
β Wallet built
β Wallet synced with sufficient balance: 500000000 tDUST
β Deployed PassportContract at 0200ec9f9121540d2dbcc205d269f0920895a20b9572699d34551e5e98004c6f1488
β Initialized PassportContract! (Tx ID: 00000000f915af09ffc517e178bed6fbcd433cc353a31f1e5ccb8b68901e30f901a391e1)
π All deployments complete!
Deployment Summary:
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Contract Name β Address β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β PassportContract β 0200ec9f9121540d2dbcc205d269f0920895a20b9572699d34551e5e98004c6f1488 β
ββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β¨ Deployment artifacts saved to deployments.jsonmidnight-deploy/
βββ dist/ # Compiled JavaScript output
βββ example/
β βββ contracts/
β β βββ Passport.compact # Example contract source
β βββ .env # Example environment variables
β βββ midnight.config.ts # Example deployment configuration
βββ node_modules/ # Project dependencies
βββ src/
β βββ cli.ts # CLI command definitions
β βββ config.ts # Configuration types and helper
β βββ deploy.ts # Core deployment logic
β βββ generate-wallet.ts # Wallet generation logic
β βββ providers.ts # Midnight.js provider setup
βββ package.json # Project metadata and scripts
βββ tsconfig.json # TypeScript configuration
βββ deployments.json # Auto-generated: stores deployed contract addresses
We welcome contributions! Feel free to open issues or submit pull requests.
- Report Issues: For bugs or feature requests, please use the GitHub Issues page.
- Get Help: Connect with the Midnight Network community on Discord for support.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
A huge thank you to the Midnight Network team for building a privacy-first blockchain and for the foundational examples that inspired this tool.