A collection of starter dapps on the Midnight Network
This monorepo contains experimental sample projects built on top of the Midnight Network using Compact. It includes contract, utility, and application code.
Check out LunarSwap, a proof of concept DEX.
- Node.js: Version 22.14.0 (see
.nvmrcandpackage.jsonengines). - pnpm: Version 10.4.1 (specified in
packageManager). - Compact Developer Tools: Required to compile
.compactsmart contracts.
Install Node.js 22.x using nvm:
nvm install 22.14.0
nvm use 22.14.0Install the Compact Developer Tools following the instructions at: https://docs.midnight.network/blog/compact-developer-tools
Verify the installation:
compact --version-
Clone the Repository:
git clone <repository-url> cd openzeppelin-midnight-apps
-
Install Dependencies:
pnpm install
- This installs all workspace dependencies and runs the
preparescript, which sets up Husky and builds@openzeppelin/midnight-apps-compact.
- This installs all workspace dependencies and runs the
-
Workspace Structure:
contracts/*: Compact Smart contract projects (e.g.,@openzeppelin/midnight-apps-access-contract).packages/*: Utility packages (e.g.,@openzeppelin/midnight-apps-compact).apps/*: Frontend applications (e.g.,@openzeppelin/midnight-apps-lunarswap-ui).
See
pnpm-workspace.yamlfor the full list. -
Build Contracts Packages:
# Navigate to each contract package and run build cd contracts/access && pnpm build cd ../math && pnpm build cd ../structs && pnpm build
- Note: Running
pnpm build:contracts,pnpm compact,pnpm compact:fast,pnpm compact:version, orpnpm compact:language-versionfrom the root may cause repetitive output due to Turbo's logging behavior. It's recommended to compile contracts individually from within each package directory. - Feature Request: A logging output mode flag is being requested to fix Turbo animation log flooding. See GitHub Issue #1188 for more details.
- Note: Running
Turbo manages tasks across the monorepo, defined in turbo.json. Key tasks:
-
compact:- Compiles
.compactfiles using the Compact CLI. - Run:
pnpm compact(from within individual packages). - Note: Running from root with
pnpm compact,pnpm compact:fast,pnpm compact:version, orpnpm compact:language-versionmay cause output repetition issues. - Variants:
pnpm compact:fast: Compiles with--skip-zkflag for faster builds.pnpm compact:fmt: Formats all.compactfiles usingcompact format.
- Compiles
-
build:build:contracts- Builds contracts projects, including TypeScript compilation and artifact copying, after running
compact. - Run:
pnpm build:contracts(may cause output repetition - use individual package compilation instead). - Dependencies: Ensures
compacttasks complete first.
- Builds contracts projects, including TypeScript compilation and artifact copying, after running
build:apps- Builds apps projects.
- Run:
pnpm build:apps.
-
test:- Runs tests with Vitest.
- Run:
pnpm test.
-
types:- Checks TypeScript types without emitting files.
- Run:
pnpm types.
-
fmt,lint,lint:fix:pnpm fmt: Formats TypeScript/JavaScript code with Biome and.compactfiles with Compact CLI.pnpm lint: Lints code with Biome.pnpm lint:fix: Auto-fixes linting issues with Biome.
Commits are linted with commitlint and staged files are processed with lint-staged and Biome.
-
Conventional Commits:
- Use the format:
<type>(<scope>): <description>(e.g.,feat(ui): add button styles). - Types:
feat,fix,docs,style,refactor,test,chore, etc. - See Conventional Commits.
- Use the format:
-
Pre-Commit Hook:
- Runs
turbo run precommitvia.husky/pre-commit. - For
@openzeppelin/midnight-apps-access-contract:lint-staged: Formats and lints staged files (see.lintstagedrc.json).pnpm run types: Checks TypeScript types.
- Runs
-
Commit Message Hook:
- Runs
commitlintvia.husky/commit-msg. - Enforces conventional commits, ignoring Dependabot messages (see
commitlint.config.ts).
- Runs
git add .
git commit -m "chore: enhance dev flow"Output:
husky - pre-commit hook
> turbo run precommit
• Running precommit in X packages
• @openzeppelin/midnight-apps-access-contract:precommit
Tasks: 1 successful, 1 total
Time: 500ms
husky - commit-msg hook
[chore/enhance-dev 123abcd] chore: enhance dev flow
git commit -m "invalid"husky - commit-msg hook
⧺ invalid
⧺ Commit message does not follow Conventional Commits format.