create-mn-app 0.3.14 → 0.3.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mn-app",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "description": "Create Midnight Network applications with zero configuration",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -8,7 +8,7 @@
8
8
  "scripts": {
9
9
  "compile": "compact compile contracts/hello-world.compact contracts/managed/hello-world",
10
10
  "build": "npx tsc --noEmit || true",
11
- "setup": "docker compose up -d && echo 'Waiting for proof server...' && sleep 5 && npm run compile && npm run deploy",
11
+ "setup": "docker compose up -d && npm run compile && npm run deploy",
12
12
  "deploy": "npx tsx src/deploy.ts",
13
13
  "cli": "npx tsx src/cli.ts",
14
14
  "check-balance": "npx tsx src/check-balance.ts",
@@ -43,6 +43,27 @@ const CONFIG = {
43
43
  faucetUrl: 'https://faucet.preprod.midnight.network/',
44
44
  };
45
45
 
46
+ // ─── Proof Server Health Check ─────────────────────────────────────────────────
47
+
48
+ async function waitForProofServer(maxAttempts = 30, delayMs = 2000): Promise<boolean> {
49
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
50
+ try {
51
+ const response = await fetch(`${CONFIG.proofServer}/health`, {
52
+ method: 'GET',
53
+ signal: AbortSignal.timeout(3000),
54
+ });
55
+ if (response.ok) return true;
56
+ } catch {
57
+ // Server not ready yet
58
+ }
59
+ if (attempt < maxAttempts) {
60
+ process.stdout.write(`\r Waiting for proof server... (${attempt}/${maxAttempts}) `);
61
+ await new Promise((r) => setTimeout(r, delayMs));
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+
46
67
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
47
68
  const zkConfigPath = path.resolve(__dirname, '..', 'contracts', 'managed', 'hello-world');
48
69
 
@@ -280,13 +301,38 @@ async function main() {
280
301
 
281
302
  // 4. Deploy contract
282
303
  console.log('─── Step 4: Deploy Contract ────────────────────────────────────\n');
304
+
305
+ // Check proof server is running
306
+ console.log(' Checking proof server...');
307
+ const proofServerReady = await waitForProofServer();
308
+ if (!proofServerReady) {
309
+ console.log('\n ❌ Proof server not responding\n');
310
+ console.log(' The proof server is required to generate zk-proofs for transactions.\n');
311
+ console.log(' ┌─ Start it with ──────────────────────────────────────────────┐');
312
+ console.log(' │ │');
313
+ console.log(' │ $ docker compose up -d │');
314
+ console.log(' │ │');
315
+ console.log(' │ Then retry: $ npm run deploy │');
316
+ console.log(' │ │');
317
+ console.log(' └──────────────────────────────────────────────────────────────┘\n');
318
+
319
+ // Save seed for retry
320
+ const partialInfo = { seed, address, network: 'preprod', status: 'proof_server_unavailable' };
321
+ fs.writeFileSync('deployment.json', JSON.stringify(partialInfo, null, 2));
322
+ console.log(' Wallet saved to deployment.json\n');
323
+
324
+ await walletCtx.wallet.stop();
325
+ process.exit(1);
326
+ }
327
+ process.stdout.write('\r Proof server ready! \n');
328
+
283
329
  console.log(' Setting up providers...');
284
330
  const providers = await createProviders(walletCtx);
285
331
 
286
332
  console.log(' Deploying contract...\n');
287
333
 
288
- const MAX_RETRIES = 5;
289
- const RETRY_DELAY_MS = 30000; // 30 seconds between retries
334
+ const MAX_RETRIES = 8;
335
+ const RETRY_DELAY_MS = 15000; // 15 seconds between retries
290
336
 
291
337
  let deployed: Awaited<ReturnType<typeof deployContract>> | undefined;
292
338
 
@@ -300,36 +346,75 @@ async function main() {
300
346
  break; // Success - exit retry loop
301
347
  } catch (err: any) {
302
348
  const errMsg = err?.message || err?.toString() || '';
349
+ const errCause = err?.cause?.message || err?.cause?.toString() || '';
350
+ const fullError = `${errMsg} ${errCause}`;
351
+
352
+ // Check for proof server errors first
353
+ if (fullError.includes('Failed to connect to Proof Server') ||
354
+ fullError.includes('Failed to prove') ||
355
+ fullError.includes('127.0.0.1:6300')) {
356
+ console.log(' ❌ Proof server error\n');
357
+ console.log(' The proof server may have stopped or crashed.\n');
358
+ console.log(' ┌─ Fix ────────────────────────────────────────────────────────┐');
359
+ console.log(' │ │');
360
+ console.log(' │ 1. Check if running: $ docker ps │');
361
+ console.log(' │ 2. Restart: $ docker compose up -d │');
362
+ console.log(' │ 3. Retry: $ npm run deploy │');
363
+ console.log(' │ │');
364
+ console.log(' └──────────────────────────────────────────────────────────────┘\n');
365
+
366
+ const partialInfo = { seed, address, network: 'preprod', status: 'proof_server_error' };
367
+ fs.writeFileSync('deployment.json', JSON.stringify(partialInfo, null, 2));
368
+ console.log(' Wallet saved to deployment.json\n');
369
+
370
+ await walletCtx.wallet.stop();
371
+ process.exit(1);
372
+ }
373
+
374
+ // Check if it's a DUST-related error (must check "Not enough Dust" specifically)
375
+ if (fullError.includes('Not enough Dust')) {
376
+ // Get current DUST balance
377
+ const currentState = await Rx.firstValueFrom(walletCtx.wallet.state().pipe(Rx.filter((s) => s.isSynced)));
378
+ const dustBalance = currentState.dust.walletBalance(new Date());
303
379
 
304
- // Check if it's a DUST-related error
305
- if (errMsg.includes('Not enough Dust') || errMsg.includes('Wallet.Transacting')) {
306
380
  if (attempt < MAX_RETRIES) {
307
- console.log(` ⏳ Waiting for more DUST to generate (attempt ${attempt}/${MAX_RETRIES})...`);
308
- console.log(' DUST generates as blocks are produced (~30s per block)');
309
- console.log(` Retrying in ${RETRY_DELAY_MS / 1000}s...\n`);
381
+ console.log(` ⏳ DUST balance: ${dustBalance.toLocaleString()} (need more for tx fees)`);
382
+ console.log(` Attempt ${attempt}/${MAX_RETRIES} - waiting for DUST to accumulate...`);
310
383
 
311
384
  // Countdown display
312
385
  for (let i = RETRY_DELAY_MS / 1000; i > 0; i -= 5) {
386
+ process.stdout.write(`\r Retrying in ${i}s... `);
313
387
  await new Promise((r) => setTimeout(r, 5000));
314
- if (i > 5) process.stdout.write(`\r ${i - 5}s remaining... `);
315
388
  }
316
- process.stdout.write('\r \r');
389
+ process.stdout.write('\r \r\n');
317
390
  } else {
318
391
  // All retries exhausted
319
- console.log(' ❌ Not enough DUST generated yet.\n');
320
- console.log(' DUST is generated over time as blocks are produced.');
321
- console.log(' Your wallet and funds are saved - just retry later:\n');
322
- console.log(' $ npm run deploy\n');
392
+ console.log(' ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
393
+ console.log(' Not enough DUST for transaction fees\n');
394
+ console.log(` Current DUST: ${dustBalance.toLocaleString()}`);
395
+ console.log(' This is a new wallet - DUST generates over time.\n');
396
+ console.log(' ┌─ Options ─────────────────────────────────────────────────┐');
397
+ console.log(' │ │');
398
+ console.log(' │ [1] Wait & retry $ npm run deploy │');
399
+ console.log(' │ (DUST accumulates as blocks are produced) │');
400
+ console.log(' │ │');
401
+ console.log(' │ [2] Send DUST from existing wallet to this address: │');
402
+ console.log(` │ ${address.slice(0, 50)}... │`);
403
+ console.log(' │ │');
404
+ console.log(' │ [3] Import wallet with DUST (choose option 2 on retry) │');
405
+ console.log(' │ │');
406
+ console.log(' └───────────────────────────────────────────────────────────┘\n');
323
407
 
324
408
  // Save partial deployment info so user can resume
325
409
  const partialInfo = {
326
410
  seed,
411
+ address,
327
412
  network: 'preprod',
328
413
  status: 'pending_dust',
329
414
  lastAttempt: new Date().toISOString(),
330
415
  };
331
416
  fs.writeFileSync('deployment.json', JSON.stringify(partialInfo, null, 2));
332
- console.log(' Seed saved to deployment.json for retry.\n');
417
+ console.log(' Wallet saved to deployment.json\n');
333
418
 
334
419
  await walletCtx.wallet.stop();
335
420
  process.exit(1);