create-mn-app 1.0.2 ā 1.0.4
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
|
@@ -87,6 +87,10 @@ Builds your TypeScript source code to JavaScript in the `dist/` directory
|
|
|
87
87
|
|
|
88
88
|
Deploys your compiled contract to the Midnight testnet
|
|
89
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
|
+
|
|
90
94
|
## Project Structure
|
|
91
95
|
|
|
92
96
|
```
|
|
@@ -176,6 +180,24 @@ PROOF_SERVER_URL=http://localhost:6300
|
|
|
176
180
|
|
|
177
181
|
## Troubleshooting
|
|
178
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
|
+
|
|
179
201
|
### Port 6300 already in use
|
|
180
202
|
|
|
181
203
|
If you see "Bind for 0.0.0.0:6300 failed: port is already allocated":
|
package/package.json
CHANGED
|
@@ -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",
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
"@midnight-ntwrk/wallet-api": "5.0.0",
|
|
34
35
|
"@midnight-ntwrk/zswap": "^4.0.0",
|
|
35
36
|
"ws": "^8.18.3",
|
|
36
|
-
"dotenv": "^16.3.1"
|
|
37
|
+
"dotenv": "^16.3.1",
|
|
38
|
+
"chalk": "^5.3.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
41
|
"@types/node": "^24.4.0",
|
|
@@ -0,0 +1,116 @@
|
|
|
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 chalk from "chalk";
|
|
13
|
+
import { MidnightProviders } from "./providers/midnight-providers.js";
|
|
14
|
+
import { EnvironmentManager } from "./utils/environment.js";
|
|
15
|
+
|
|
16
|
+
// Fix WebSocket for Node.js environment
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
globalThis.WebSocket = WebSocket;
|
|
19
|
+
|
|
20
|
+
// Configure for Midnight Testnet
|
|
21
|
+
setNetworkId(NetworkId.TestNet);
|
|
22
|
+
|
|
23
|
+
async function checkBalance() {
|
|
24
|
+
try {
|
|
25
|
+
console.log();
|
|
26
|
+
console.log(chalk.blue.bold("ā".repeat(60)));
|
|
27
|
+
console.log(chalk.blue.bold("š Wallet Balance Checker"));
|
|
28
|
+
console.log(chalk.blue.bold("ā".repeat(60)));
|
|
29
|
+
console.log();
|
|
30
|
+
|
|
31
|
+
const seed = process.env.WALLET_SEED;
|
|
32
|
+
if (!seed) {
|
|
33
|
+
throw new Error("WALLET_SEED not found in .env file");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(chalk.gray("Building wallet..."));
|
|
37
|
+
console.log();
|
|
38
|
+
|
|
39
|
+
// Get network configuration
|
|
40
|
+
const networkConfig = EnvironmentManager.getNetworkConfig();
|
|
41
|
+
|
|
42
|
+
// Create providers
|
|
43
|
+
const providers = MidnightProviders.create({
|
|
44
|
+
indexerUrl: networkConfig.indexerUrl,
|
|
45
|
+
indexerWsUrl: networkConfig.indexerWsUrl,
|
|
46
|
+
prooServerUrl: networkConfig.proofServerUrl,
|
|
47
|
+
walletSeed: seed,
|
|
48
|
+
zkConfigPath: networkConfig.zkConfigPath,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Build wallet
|
|
52
|
+
const wallet = await WalletBuilder.buildFromSeed(
|
|
53
|
+
getLedgerNetworkId(),
|
|
54
|
+
seed,
|
|
55
|
+
providers.privateStateProvider,
|
|
56
|
+
providers.zkConfigProvider,
|
|
57
|
+
providers.publicDataProvider,
|
|
58
|
+
{ coinPublicKey: providers.coinPublicKey }
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
wallet.start();
|
|
62
|
+
|
|
63
|
+
const state = await Rx.firstValueFrom(wallet.state());
|
|
64
|
+
|
|
65
|
+
console.log(chalk.cyan.bold("š Wallet Address:"));
|
|
66
|
+
console.log(chalk.white(` ${state.address}`));
|
|
67
|
+
console.log();
|
|
68
|
+
|
|
69
|
+
const balance = state.balances[nativeToken()] || 0n;
|
|
70
|
+
|
|
71
|
+
if (balance === 0n) {
|
|
72
|
+
console.log(chalk.yellow.bold("š° Balance: ") + chalk.red.bold("0 DUST"));
|
|
73
|
+
console.log();
|
|
74
|
+
console.log(chalk.red("ā No funds detected."));
|
|
75
|
+
console.log();
|
|
76
|
+
console.log(chalk.magenta.bold("ā".repeat(60)));
|
|
77
|
+
console.log(chalk.magenta.bold("š How to Get Test Tokens:"));
|
|
78
|
+
console.log(chalk.magenta.bold("ā".repeat(60)));
|
|
79
|
+
console.log();
|
|
80
|
+
console.log(chalk.white(" 1. ") + chalk.cyan("Visit: ") + chalk.underline("https://midnight.network/test-faucet"));
|
|
81
|
+
console.log(chalk.white(" 2. ") + chalk.cyan("Paste your wallet address (shown above)"));
|
|
82
|
+
console.log(chalk.white(" 3. ") + chalk.cyan("Request tokens from the faucet"));
|
|
83
|
+
console.log(chalk.white(" 4. ") + chalk.cyan("Wait 2-5 minutes for processing"));
|
|
84
|
+
console.log(chalk.white(" 5. ") + chalk.cyan("Run ") + chalk.yellow.bold("'npm run check-balance'") + chalk.cyan(" again"));
|
|
85
|
+
console.log();
|
|
86
|
+
console.log(chalk.gray("ā".repeat(60)));
|
|
87
|
+
console.log(chalk.gray("š” Tip: Faucet transactions typically take 2-5 minutes to process."));
|
|
88
|
+
console.log(chalk.gray("ā".repeat(60)));
|
|
89
|
+
} else {
|
|
90
|
+
console.log(chalk.yellow.bold("š° Balance: ") + chalk.green.bold(`${balance} DUST`));
|
|
91
|
+
console.log();
|
|
92
|
+
console.log(chalk.green.bold("ā
Wallet is funded and ready!"));
|
|
93
|
+
console.log();
|
|
94
|
+
console.log(chalk.magenta.bold("ā".repeat(60)));
|
|
95
|
+
console.log(chalk.magenta.bold("š Next Step:"));
|
|
96
|
+
console.log(chalk.magenta.bold("ā".repeat(60)));
|
|
97
|
+
console.log();
|
|
98
|
+
console.log(chalk.cyan(" Deploy your contract with:"));
|
|
99
|
+
console.log(chalk.yellow.bold(" npm run deploy"));
|
|
100
|
+
console.log();
|
|
101
|
+
console.log(chalk.gray("ā".repeat(60)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log();
|
|
105
|
+
wallet.close();
|
|
106
|
+
process.exit(0);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log();
|
|
109
|
+
console.log(chalk.red.bold("ā Error checking balance:"));
|
|
110
|
+
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
111
|
+
console.log();
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
checkBalance();
|
|
@@ -19,6 +19,7 @@ import * as fs from "fs";
|
|
|
19
19
|
import * as path from "path";
|
|
20
20
|
import * as Rx from "rxjs";
|
|
21
21
|
import { type Wallet } from "@midnight-ntwrk/wallet-api";
|
|
22
|
+
import chalk from "chalk";
|
|
22
23
|
import { MidnightProviders } from "./providers/midnight-providers.js";
|
|
23
24
|
import { EnvironmentManager } from "./utils/environment.js";
|
|
24
25
|
|
|
@@ -47,7 +48,11 @@ const waitForFunds = (wallet: Wallet) =>
|
|
|
47
48
|
);
|
|
48
49
|
|
|
49
50
|
async function main() {
|
|
50
|
-
console.log(
|
|
51
|
+
console.log();
|
|
52
|
+
console.log(chalk.blue.bold("ā".repeat(60)));
|
|
53
|
+
console.log(chalk.blue.bold("š {{projectName}} Deployment"));
|
|
54
|
+
console.log(chalk.blue.bold("ā".repeat(60)));
|
|
55
|
+
console.log();
|
|
51
56
|
|
|
52
57
|
try {
|
|
53
58
|
// Validate environment
|
|
@@ -79,23 +84,44 @@ async function main() {
|
|
|
79
84
|
wallet.start();
|
|
80
85
|
const state = await Rx.firstValueFrom(wallet.state());
|
|
81
86
|
|
|
82
|
-
console.log(
|
|
87
|
+
console.log(chalk.cyan.bold("š Wallet Address:"));
|
|
88
|
+
console.log(chalk.white(` ${state.address}`));
|
|
89
|
+
console.log();
|
|
83
90
|
|
|
84
91
|
let balance = state.balances[nativeToken()] || 0n;
|
|
85
92
|
|
|
86
93
|
if (balance === 0n) {
|
|
87
|
-
console.log(
|
|
88
|
-
console.log(
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
console.log(
|
|
94
|
+
console.log(chalk.yellow.bold("š° Balance: ") + chalk.red.bold("0 DUST"));
|
|
95
|
+
console.log();
|
|
96
|
+
console.log(chalk.red.bold("ā Wallet needs funding to deploy contracts."));
|
|
97
|
+
console.log();
|
|
98
|
+
console.log(chalk.magenta.bold("ā".repeat(60)));
|
|
99
|
+
console.log(chalk.magenta.bold("š How to Get Test Tokens:"));
|
|
100
|
+
console.log(chalk.magenta.bold("ā".repeat(60)));
|
|
101
|
+
console.log();
|
|
102
|
+
console.log(chalk.white(" 1. ") + chalk.cyan("Visit: ") + chalk.underline("https://midnight.network/test-faucet"));
|
|
103
|
+
console.log(chalk.white(" 2. ") + chalk.cyan("Paste your wallet address (shown above)"));
|
|
104
|
+
console.log(chalk.white(" 3. ") + chalk.cyan("Request tokens from the faucet"));
|
|
105
|
+
console.log();
|
|
106
|
+
console.log(chalk.gray("ā".repeat(60)));
|
|
107
|
+
console.log(chalk.gray("ā±ļø Faucet transactions can take 2-5 minutes to process."));
|
|
108
|
+
console.log(chalk.gray("ā".repeat(60)));
|
|
109
|
+
console.log();
|
|
110
|
+
console.log(chalk.yellow.bold("š” Options while waiting:"));
|
|
111
|
+
console.log(chalk.white(" ⢠") + chalk.cyan("Let this script wait (it will auto-detect when funds arrive)"));
|
|
112
|
+
console.log(chalk.white(" ⢠") + chalk.cyan("OR press ") + chalk.yellow("Ctrl+C") + chalk.cyan(" to stop, then check balance with:"));
|
|
113
|
+
console.log(chalk.yellow.bold(" npm run check-balance"));
|
|
114
|
+
console.log(chalk.white(" ⢠") + chalk.cyan("Once funded, run: ") + chalk.yellow.bold("npm run deploy"));
|
|
115
|
+
console.log();
|
|
116
|
+
console.log(chalk.blue("ā³ Waiting to receive tokens..."));
|
|
92
117
|
balance = await waitForFunds(wallet);
|
|
93
118
|
}
|
|
94
119
|
|
|
95
|
-
console.log(
|
|
120
|
+
console.log(chalk.yellow.bold("š° Balance: ") + chalk.green.bold(`${balance} DUST`));
|
|
121
|
+
console.log();
|
|
96
122
|
|
|
97
123
|
// Load compiled contract files
|
|
98
|
-
console.log("Loading contract...");
|
|
124
|
+
console.log(chalk.gray("š¦ Loading contract..."));
|
|
99
125
|
const contractPath = path.join(process.cwd(), "contracts");
|
|
100
126
|
const contractModulePath = path.join(
|
|
101
127
|
contractPath,
|
|
@@ -146,7 +172,8 @@ async function main() {
|
|
|
146
172
|
});
|
|
147
173
|
|
|
148
174
|
// Deploy contract to blockchain
|
|
149
|
-
console.log("Deploying contract (30-60 seconds)...");
|
|
175
|
+
console.log(chalk.blue("š Deploying contract (30-60 seconds)..."));
|
|
176
|
+
console.log();
|
|
150
177
|
|
|
151
178
|
const deployed = await deployContract(providers, {
|
|
152
179
|
contract: contractInstance,
|
|
@@ -157,8 +184,14 @@ async function main() {
|
|
|
157
184
|
const contractAddress = deployed.deployTxData.public.contractAddress;
|
|
158
185
|
|
|
159
186
|
// Save deployment information
|
|
160
|
-
console.log(
|
|
161
|
-
console.log(
|
|
187
|
+
console.log();
|
|
188
|
+
console.log(chalk.green.bold("ā".repeat(60)));
|
|
189
|
+
console.log(chalk.green.bold("š CONTRACT DEPLOYED SUCCESSFULLY!"));
|
|
190
|
+
console.log(chalk.green.bold("ā".repeat(60)));
|
|
191
|
+
console.log();
|
|
192
|
+
console.log(chalk.cyan.bold("š Contract Address:"));
|
|
193
|
+
console.log(chalk.white(` ${contractAddress}`));
|
|
194
|
+
console.log();
|
|
162
195
|
|
|
163
196
|
const info = {
|
|
164
197
|
contractAddress,
|
|
@@ -168,12 +201,16 @@ async function main() {
|
|
|
168
201
|
};
|
|
169
202
|
|
|
170
203
|
fs.writeFileSync("deployment.json", JSON.stringify(info, null, 2));
|
|
171
|
-
console.log("ā
Saved to deployment.json");
|
|
204
|
+
console.log(chalk.gray("ā
Saved to deployment.json"));
|
|
205
|
+
console.log();
|
|
172
206
|
|
|
173
207
|
// Close wallet connection
|
|
174
208
|
await wallet.close();
|
|
175
209
|
} catch (error) {
|
|
176
|
-
console.
|
|
210
|
+
console.log();
|
|
211
|
+
console.log(chalk.red.bold("ā Deployment Failed:"));
|
|
212
|
+
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
213
|
+
console.log();
|
|
177
214
|
process.exit(1);
|
|
178
215
|
}
|
|
179
216
|
}
|