Base template for blockchain projects on Midnight Network - A complete and modern template for developing decentralized applications (dApps) with smart contracts, backend APIs, CLI tools, and user interfaces.
- π― Description
- β¨ Features
- ποΈ Architecture
- βοΈ System Requirements
- π Installation
- π Basic Usage
- ποΈ Project Structure
- π Quick Development Guide
- π³ Docker Services
- π Running the Application
- π€ Contributing
- π License
- π Roadmap & Ideas for Improvement
Midnight Quick Starter is a complete and modern template for developing blockchain applications on the Midnight network. This template provides a solid foundation with all the necessary tools to create dApps with smart contracts, APIs, user interfaces, and CLI tools.
- β Complete dApp development on Midnight Network
- β Smart contract creation with Compact
- β Backend APIs for blockchain interaction
- β Modern user interfaces with React
- β CLI tools for development
- β Monorepo with optimized dependency management
- π§ Monorepo with Turbo - Optimized build system and dependency management
- π TypeScript - Complete static typing across all packages
- β‘ React + Vite - Modern UI with hot reload
- π Compact Contracts - Smart contracts with Compact language
- π REST/WebSocket API - Backend for blockchain interaction
- π₯οΈ CLI Tools - Command line tools
- π¨ Tailwind CSS - Modern and responsive styles
- π ESLint + Prettier - Clean and consistent code
midnight-quick-starter/
βββ π¦ packages/
β βββ π¨ ui/ # React + Vite Frontend
β βββ π§ api/ # Backend API
β βββ π₯οΈ cli/ # CLI Tools
β βββ π contract/ # Compact Contracts
βββ π§ compact/ # Compact Compiler
βββ π docs/ # Documentation
- Node.js >= 22.0.0
- Yarn >= 4.9.2
- Git >= 2.0.0
- Docker (optional, for local testing)
node --version # >= 22.0.0
yarn --version # >= 4.9.2
git --version # >= 2.0.0
# Option 1: Use "Use this template" button on GitHub
# Click "Use this template" β "Create a new repository"
# Option 2: Fork the repository
# Click "Fork" β Clone your forked repository
git clone <your-forked-repository-url>
cd midnight-quick-starter
# Option 3: Clone directly (for contributing)
git clone <repository-url>
cd midnight-quick-starter
yarn install
Before building, you need to fetch the zero-knowledge (ZK) parameters required by the proof server. This is done via a helper script that you should place in the CLI package:
# Move to the CLI package directory
cd packages/cli
# Download the fetch-zk-params.sh script
curl -O https://raw.githubusercontent.com/bricktowers/midnight-proof-server/main/fetch-zk-params.sh
# or
wget https://raw.githubusercontent.com/bricktowers/midnight-proof-server/main/fetch-zk-params.sh
# Give execution permissions
chmod +x fetch-zk-params.sh
# Run the script to download ZK parameters
./fetch-zk-params.sh
Note:
- This script will generate a folder at
/.cache/midnight/zk-params
with all the required parameters for zero-knowledge proofs.- Why is this needed? If you see an error like:
Error in response: Proving(public parameters for k=16 not found in cache)
it means the required parameters are missing.- This script is a workaround to ensure your application works locally. The Midnight team is working on a more integrated solution for parameter management in the future.
To Install the compiler in your teminal follow these steps:
Download compiler
This command will download and run a shell script. It will instruct you how to add the binary directory it uses to your PATH environment variable.
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | sh
Update compiler
Once you've done this, the compact command line tool is available to use. This tool has a number of useful subcommands that can be invoked. For instance, to update the toolchain to the latest version, you will run the command:
compact update
The output will look something like this (on an Apple Silicon macOS machine, for instance):
compact: aarch64-darwin -- 0.24.0 -- installed
compact: aarch64-darwin -- 0.24.0 -- default.
Check new version available
You can check if there is a new version available using the check subcommand like this:
compact check
If there is a new version available, you will see something like:
compact: aarch64-darwin -- Update Available -- 0.24.0
compact: Latest version available: 0.24.0.
This is reporting that you are on version 0.24.0 and that 0.25.0 is available.
Note: You will not actually see this output until there is a new version available. Instead, you will see that you are on the latest version:
compact: aarch64-darwin -- Up to date -- 0.24.0
Invoking the Compiler
In addition to keeping the toolchain updated, the compact tool will also be the official supported way to invoke all the toolchain tools themselves. For the time being, the only such tool is the compiler, but we will be building out more tools in the future. The compiler can be invoked with the compile subcommand:
compact compile <contract file> <output directory>
You can see and learn more information, commands about the compiler here: compact developer tools
# Build all packages (creates necessary folders automatically)
yarn build:all
Note: The build process automatically creates the necessary folders (
keys
andzkir
) that are required by the frontend. No manual folder creation is needed.What
yarn build:all
does:
- Builds the contract package (compiles Compact contracts)
- Builds the API package (TypeScript compilation)
- Builds the CLI package (TypeScript compilation)
- Builds the UI package (Vite build with contract assets)
- Creates necessary folders for frontend compatibility
ui/
βββ src/
β βββ components/ # React Components
β βββ hooks/ # Custom hooks
β βββ lib/ # Utilities
β βββ providers/ # Context providers
β βββ assets/ # Static resources
βββ public/ # Public files
βββ dist/ # Production build
api/
βββ src/
β βββ index.ts # Entry point
β βββ test/ # Tests
βββ dist/ # Compiled build
contract/
βββ src/
β βββ quick-starter.compact # Main contract
β βββ managed/ # Generated contracts
β βββ index.ts # Exports
βββ dist/ # Compiled build
cli/
βββ src/
β βββ launcher/ # Network launchers
β βββ config.ts # Configurations
β βββ index.ts # Entry point
βββ dist/ # Compiled build
turbo.json
- Monorepo configurationpackage.json
- Root dependencies and scripts.eslintrc.js
- Linting rulestsconfig.json
- TypeScript configuration
To quickly find areas that need customization, search for TODO
comments throughout the codebase:
Using your code editor's global search:
- VS Code:
Ctrl+Shift+F
(orCmd+Shift+F
on Mac) and search forTODO
- WebStorm/IntelliJ:
Ctrl+Shift+F
and search forTODO
- Sublime Text:
Ctrl+Shift+F
and search forTODO
Using command line:
# Search for all TODO comments
grep -r "TODO" .
# Or search in specific packages
grep -r "TODO" packages/contract/
grep -r "TODO" packages/api/
grep -r "TODO" packages/ui/
grep -r "TODO" packages/cli/
packages/contract/src/quick-starter.compact
- Your main smart contractpackages/contract/src/index.ts
- Contract exports and logicpackages/api/src/index.ts
- Backend API implementationpackages/cli/src/index.ts
- CLI interaction logicpackages/ui/src/main.tsx
- Main React applicationpackages/ui/src/components/
- React componentspackages/ui/src/hooks/
- Custom React hookspackages/ui/src/lib/
- Utility functionspackages/ui/src/providers/
- Context providers
- Edit your contract in
packages/contract/src/quick-starter.compact
- Build the contract with
cd packages/contract && npx turbo run build
- Build other packages as needed using individual build commands
- Customize UI components in
packages/ui/src/
- Implement API logic in
packages/api/src/
After building your packages, you can run the Infrastructure services using Docker:
cd packages/cli
docker compose -f testnet.yml up -d
cd packages/cli
docker compose -f standalone.yml up -d
Note: The
-d
flag runs containers in detached mode (background), so you can continue using your terminal.
You should see something like:
β Container quick-starter-proof-server Started
β Container quick-starter-node Started
β Container quick-starter-indexer Started
cd packages/ui
yarn start
The application will be available at localhost:8080
This is a template designed to be used as a starting point for new projects. You can:
- Use as Template - Click "Use this template" to create a new repository
- Fork the repository for your own project
- Contribute - Any PR is welcome to improve the template
If contributing:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Use TypeScript for all code
- Follow configured ESLint and Prettier
- Write tests for new features
- Document APIs and complex functions
feat: new feature
fix: bug fix
docs: documentation
style: code formatting
refactor: refactoring
test: tests
chore: maintenance tasks
This project is licensed under the MIT License. See the LICENSE file for details.
This template is designed to be a living project and welcomes suggestions and contributions for new features and improvements. Here are some ideas and known areas for future enhancement:
-
Integrated ZK Parameter Management:
Instead of requiring a manual script, the ZK parameters could be downloaded automatically as part of the Docker image or build process.
The infrastructure could check for missing parameters and fetch them on demand. -
Better Developer Onboarding:
Add interactive setup scripts or a CLI wizard for first-time setup.
Provide more example contracts, API endpoints, and UI components. -
Automated Environment Checks:
Add pre-build checks for required tools, environment variables, and folder structure. -
Improved Error Handling:
More descriptive error messages and troubleshooting guides for common issues. -
Template Customization Tools:
Scripts to easily rename the template, update package names, and clean up example files. -
CI/CD Integration:
Add GitHub Actions or other CI pipelines for automated testing, linting, and deployment. -
Documentation Enhancements:
More diagrams, architecture overviews, and real-world usage examples. -
Community Feedback:
Encourage users to open issues or discussions for feature requests and pain points. -
Unified CLI/Library for Project Management:
Create a library or CLI tool to automate all setup, configuration, and project management from a single command (e.g., midnight-quick-starter init). -
Basic Hello World Contract Validation:
Add a minimal contract and test that simply sets and reads a "Hello World" message to validate that the toolchain and build are working correctly. -
Lace Beta Wallet Integration:
Add support and documentation for integrating with Lace Beta Wallet for user authentication and transaction signing in the UI.
Have an idea? Open an issue or pull request to help make this template even better!
If you have issues or questions:
- Check the documentation
- Search existing issues
- Create a new issue
- Midnight Network Documentation
- Compact Language Guide
- Turbo Documentation
- React Documentation
- TypeScript Documentation
β If this template is useful to you, consider giving the repository a star!
Made with β€οΈ by the Midnight ecosystem