create-mn-app 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,45 +1,247 @@
1
- # create-midnight-app
1
+ # create-mn-app šŸŒ™
2
2
 
3
3
  Create Midnight Network applications with zero configuration.
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/create-mn-app.svg)](https://www.npmjs.com/package/create-mn-app)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
5
8
  ```bash
6
- npx create-midnight-app my-app
9
+ npx create-mn-app my-app
7
10
  cd my-app
8
11
  npm run dev
9
12
  ```
10
13
 
11
14
  ## Features
12
15
 
13
- - ⚔ **Zero configuration** - Works out of the box
16
+ - ⚔ **Zero configuration** - Works out of the box with sensible defaults
14
17
  - šŸ”§ **Modern tooling** - TypeScript, hot reloading, auto-compilation
15
18
  - šŸ›”ļø **Best practices** - Secure wallet generation, proper project structure
16
19
  - šŸš€ **Fast setup** - From zero to working app in 60 seconds
17
20
  - šŸŽÆ **Developer friendly** - Clear error messages, helpful guides
21
+ - šŸ“¦ **ES Modules** - Modern JavaScript module system
22
+ - 🐳 **Docker integration** - Automated proof server setup
18
23
 
19
24
  ## Quick Start
20
25
 
21
26
  ```bash
22
- # Create new app
23
- npx create-midnight-app my-midnight-app
27
+ # Create a new Midnight app
28
+ npx create-mn-app my-midnight-app
24
29
 
25
- # Enter directory
30
+ # Navigate to your project
26
31
  cd my-midnight-app
27
32
 
28
- # Start development
33
+ # Start development server with hot reloading
29
34
  npm run dev
30
35
  ```
31
36
 
37
+ ## What's Included?
38
+
39
+ Your generated project includes:
40
+
41
+ - šŸ“ **Hello World Contract** - A simple Compact contract to get started
42
+ - šŸ” **Wallet Setup** - Auto-generated wallet with secure seed phrase
43
+ - šŸ› ļø **Development Environment** - Pre-configured TypeScript, nodemon, and build tools
44
+ - šŸ“š **Provider Setup** - Midnight network providers (indexer, proof, state, ZK config)
45
+ - šŸŽØ **Interactive CLI** - Test your contracts with a user-friendly command-line interface
46
+ - šŸ“‹ **Environment Config** - `.env` file with network configuration
47
+ - šŸ”„ **Git Ready** - Initialized git repository with proper `.gitignore`
48
+
49
+ ## Available Commands
50
+
51
+ Once your project is created, you can run:
52
+
53
+ ### `npm run dev`
54
+
55
+ Starts the development server with:
56
+
57
+ - Docker-based proof server on port 6300
58
+ - File watcher for automatic recompilation
59
+ - Hot reloading for contract changes
60
+
61
+ ### `npm run setup`
62
+
63
+ Complete setup pipeline:
64
+
65
+ 1. Compiles Compact contracts
66
+ 2. Builds TypeScript to JavaScript
67
+ 3. Deploys contracts to the network
68
+
69
+ ### `npm run cli`
70
+
71
+ Opens an interactive command-line interface to:
72
+
73
+ - Connect your wallet
74
+ - Store messages in the contract
75
+ - Retrieve stored messages
76
+ - Test contract functionality
77
+
78
+ ### `npm run compile`
79
+
80
+ Compiles your Compact smart contracts from `contracts/` to `contracts/managed/`
81
+
82
+ ### `npm run build`
83
+
84
+ Builds your TypeScript source code to JavaScript in the `dist/` directory
85
+
86
+ ### `npm run deploy`
87
+
88
+ Deploys your compiled contract to the Midnight testnet
89
+
90
+ ### `npm run check-balance`
91
+
92
+ Checks your wallet balance. Useful for verifying if test tokens from the faucet have arrived before deploying.
93
+
94
+ ## Project Structure
95
+
96
+ ```
97
+ my-midnight-app/
98
+ ā”œā”€ā”€ contracts/
99
+ │ ā”œā”€ā”€ hello-world.compact # Your Compact smart contract
100
+ │ └── managed/ # Compiled contract output
101
+ ā”œā”€ā”€ src/
102
+ │ ā”œā”€ā”€ cli.ts # Interactive CLI application
103
+ │ ā”œā”€ā”€ deploy.ts # Contract deployment script
104
+ │ ā”œā”€ā”€ providers/
105
+ │ │ └── midnight-providers.ts # Network provider configuration
106
+ │ └── utils/
107
+ │ └── environment.ts # Environment management
108
+ ā”œā”€ā”€ .env # Environment variables & wallet seed
109
+ ā”œā”€ā”€ .gitignore
110
+ ā”œā”€ā”€ package.json
111
+ ā”œā”€ā”€ tsconfig.json
112
+ └── nodemon.json
113
+ ```
114
+
32
115
  ## Templates
33
116
 
34
- - **hello-world** (default) - Simple message storage contract
35
- - More templates coming soon!
117
+ ### Hello World (Default)
118
+
119
+ A simple message storage contract demonstrating:
120
+
121
+ - State management
122
+ - Public and private data
123
+ - Contract deployment
124
+ - Interactive testing
125
+
126
+ **More templates coming soon!**
36
127
 
37
128
  ## Requirements
38
129
 
39
- - Node.js 18+
40
- - Docker (for proof server)
130
+ - **Node.js** 18.0.0 or higher
131
+ - **Docker** (for running the proof server)
132
+ - **npm**, **yarn**, or **pnpm** package manager
133
+
134
+ ## Package Manager Options
135
+
136
+ You can use your preferred package manager:
137
+
138
+ ```bash
139
+ # npm (default)
140
+ npx create-mn-app my-app
141
+
142
+ # Yarn
143
+ npx create-mn-app my-app --yarn
144
+
145
+ # pnpm
146
+ npx create-mn-app my-app --pnpm
147
+ ```
148
+
149
+ ## Usage Options
150
+
151
+ ```bash
152
+ npx create-mn-app [project-name] [options]
153
+
154
+ Options:
155
+ --template <name> Specify a template (default: hello-world)
156
+ --yarn Use Yarn as package manager
157
+ --pnpm Use pnpm as package manager
158
+ --npm Use npm as package manager
159
+ --skip-install Skip dependency installation
160
+ --skip-git Skip git initialization
161
+ -h, --help Display help information
162
+ ```
163
+
164
+ ## Environment Configuration
165
+
166
+ Your `.env` file contains important configuration:
167
+
168
+ ```env
169
+ # Wallet Configuration
170
+ WALLET_SEED=your-generated-seed-phrase
171
+
172
+ # Network Configuration
173
+ MIDNIGHT_NETWORK=testnet
174
+ INDEXER_URL=https://indexer.testnet.midnight.network
175
+ INDEXER_WS_URL=wss://indexer.testnet.midnight.network
176
+ PROOF_SERVER_URL=http://localhost:6300
177
+ ```
178
+
179
+ āš ļø **Important**: Never commit your `.env` file or share your wallet seed phrase!
180
+
181
+ ## Troubleshooting
182
+
183
+ ### Waiting for faucet funds
184
+
185
+ If your deployment is waiting for funds from the testnet faucet:
186
+
187
+ ```bash
188
+ # Option 1: Let the script wait (it will auto-detect funds)
189
+ # Just leave it running after requesting from the faucet
190
+
191
+ # Option 2: Stop and check manually
192
+ # Press Ctrl+C to stop, then:
193
+ npm run check-balance
194
+
195
+ # Once funded, deploy:
196
+ npm run deploy
197
+ ```
198
+
199
+ šŸ’” **Note**: Faucet transactions typically take 2-5 minutes to process.
200
+
201
+ ### Port 6300 already in use
202
+
203
+ If you see "Bind for 0.0.0.0:6300 failed: port is already allocated":
204
+
205
+ ```bash
206
+ # Stop the existing proof server
207
+ docker ps
208
+ docker stop <container-id>
209
+
210
+ # Or run on a different port (update .env accordingly)
211
+ ```
212
+
213
+ ### Module resolution errors
214
+
215
+ Make sure you're using Node.js 18+ and the project was created with the latest version:
216
+
217
+ ```bash
218
+ node --version
219
+ npx create-mn-app@latest my-app
220
+ ```
221
+
222
+ ### Docker not running
223
+
224
+ Ensure Docker Desktop is running before starting the development server:
225
+
226
+ ```bash
227
+ docker --version
228
+ ```
41
229
 
42
230
  ## Learn More
43
231
 
44
- - [Midnight Documentation](https://docs.midnight.network)
45
- - [Getting Started Guide](https://docs.midnight.network/getting-started)
232
+ - šŸ“– [Midnight Documentation](https://docs.midnight.network)
233
+ - šŸš€ [Getting Started Guide](https://docs.midnight.network/getting-started)
234
+ - šŸ’¬ [Midnight Discord Community](https://discord.gg/midnight)
235
+ - šŸ™ [GitHub Repository](https://github.com/Olanetsoft/create-midnight-app)
236
+
237
+ ## Contributing
238
+
239
+ Contributions are welcome! Please feel free to submit a Pull Request.
240
+
241
+ ## License
242
+
243
+ MIT Ā© [Olanetsoft](https://github.com/Olanetsoft)
244
+
245
+ ---
246
+
247
+ Built with ā¤ļø for the Midnight Network community šŸŒ™āœØ
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mn-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Create Midnight Network applications with zero configuration",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -13,6 +13,7 @@
13
13
  "build": "tsc",
14
14
  "deploy": "node dist/deploy.js",
15
15
  "cli": "node dist/cli.js",
16
+ "check-balance": "npm run build && node dist/check-balance.js",
16
17
  "reset": "rm -rf contracts/managed deployment.json dist && npm run compile",
17
18
  "validate": "tsc --noEmit && npm run compile",
18
19
  "clean": "rm -rf dist contracts/managed deployment.json",
@@ -0,0 +1,87 @@
1
+ import "dotenv/config";
2
+ import { WalletBuilder } from "@midnight-ntwrk/wallet";
3
+ import {
4
+ NetworkId,
5
+ setNetworkId,
6
+ getZswapNetworkId,
7
+ getLedgerNetworkId,
8
+ } from "@midnight-ntwrk/midnight-js-network-id";
9
+ import { nativeToken } from "@midnight-ntwrk/ledger";
10
+ import { WebSocket } from "ws";
11
+ import * as Rx from "rxjs";
12
+ import { MidnightProviders } from "./providers/midnight-providers.js";
13
+ import { EnvironmentManager } from "./utils/environment.js";
14
+
15
+ // Fix WebSocket for Node.js environment
16
+ // @ts-ignore
17
+ globalThis.WebSocket = WebSocket;
18
+
19
+ // Configure for Midnight Testnet
20
+ setNetworkId(NetworkId.TestNet);
21
+
22
+ async function checkBalance() {
23
+ try {
24
+ console.log("\nšŸŒ™ Checking Wallet Balance\n");
25
+
26
+ const seed = process.env.WALLET_SEED;
27
+ if (!seed) {
28
+ throw new Error("WALLET_SEED not found in .env file");
29
+ }
30
+
31
+ console.log("Building wallet...");
32
+
33
+ // Get network configuration
34
+ const networkConfig = EnvironmentManager.getNetworkConfig();
35
+
36
+ // Create providers
37
+ const providers = MidnightProviders.create({
38
+ indexerUrl: networkConfig.indexerUrl,
39
+ indexerWsUrl: networkConfig.indexerWsUrl,
40
+ prooServerUrl: networkConfig.proofServerUrl,
41
+ walletSeed: seed,
42
+ zkConfigPath: networkConfig.zkConfigPath,
43
+ });
44
+
45
+ // Build wallet
46
+ const wallet = await WalletBuilder.buildFromSeed(
47
+ getLedgerNetworkId(),
48
+ seed,
49
+ providers.privateStateProvider,
50
+ providers.zkConfigProvider,
51
+ providers.publicDataProvider,
52
+ { coinPublicKey: providers.coinPublicKey }
53
+ );
54
+
55
+ wallet.start();
56
+
57
+ const state = await Rx.firstValueFrom(wallet.state());
58
+
59
+ console.log(`Wallet Address: ${state.address}`);
60
+
61
+ const balance = state.balances[nativeToken()] || 0n;
62
+
63
+ if (balance === 0n) {
64
+ console.log(`\nšŸ’° Balance: 0 DUST\n`);
65
+ console.log("āŒ No funds detected.");
66
+ console.log("\nšŸ“ To get funds:");
67
+ console.log(" 1. Visit: https://midnight.network/test-faucet");
68
+ console.log(" 2. Paste your wallet address");
69
+ console.log(" 3. Wait a few minutes for the transaction to process");
70
+ console.log(" 4. Run 'npm run check-balance' again to verify");
71
+ console.log("\nšŸ’” Note: Faucet transactions can take 2-5 minutes to process.");
72
+ } else {
73
+ console.log(`\nšŸ’° Balance: ${balance} DUST\n`);
74
+ console.log("āœ… Wallet is funded!");
75
+ console.log("\nšŸš€ You can now deploy your contract:");
76
+ console.log(" npm run deploy");
77
+ }
78
+
79
+ wallet.close();
80
+ process.exit(0);
81
+ } catch (error) {
82
+ console.error("Error checking balance:", error);
83
+ process.exit(1);
84
+ }
85
+ }
86
+
87
+ checkBalance();
@@ -84,10 +84,18 @@ async function main() {
84
84
  let balance = state.balances[nativeToken()] || 0n;
85
85
 
86
86
  if (balance === 0n) {
87
- console.log(`Your wallet balance is: 0`);
88
- console.log(
89
- "Visit: https://midnight.network/test-faucet to get some funds."
90
- );
87
+ console.log(`Your wallet balance is: 0 DUST`);
88
+ console.log("\nāŒ Wallet needs funding to deploy contracts.\n");
89
+ console.log("šŸ“ To get test tokens:");
90
+ console.log(" 1. Visit: https://midnight.network/test-faucet");
91
+ console.log(" 2. Paste your wallet address (shown above)");
92
+ console.log(" 3. Request tokens from the faucet\n");
93
+ console.log("ā±ļø Faucet transactions can take 2-5 minutes to process.\n");
94
+ console.log("šŸ’” Options while waiting:");
95
+ console.log(" • Let this script wait (it will auto-detect when funds arrive)");
96
+ console.log(" • OR press Ctrl+C to stop, then check balance with:");
97
+ console.log(" npm run check-balance");
98
+ console.log(" • Once funded, run: npm run deploy\n");
91
99
  console.log(`Waiting to receive tokens...`);
92
100
  balance = await waitForFunds(wallet);
93
101
  }