Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit 4fd4dca

Browse files
committed
feat: add check-balance command and improve faucet funding instructions
- Added new 'npm run check-balance' command to verify wallet balance - Created check-balance.ts template for standalone balance checking - Improved deploy script messaging with clearer faucet instructions - Added guidance for handling faucet transaction delays (2-5 minutes) - Updated README with check-balance command and troubleshooting - Provides users with options: wait for auto-detection or manually check
1 parent dcbb129 commit 4fd4dca

File tree

5 files changed

+123
-5
lines changed

5 files changed

+123
-5
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ Builds your TypeScript source code to JavaScript in the `dist/` directory
8787

8888
Deploys your compiled contract to the Midnight testnet
8989

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+
9094
## Project Structure
9195

9296
```
@@ -176,6 +180,24 @@ PROOF_SERVER_URL=http://localhost:6300
176180

177181
## Troubleshooting
178182

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+
179201
### Port 6300 already in use
180202

181203
If you see "Bind for 0.0.0.0:6300 failed: port is already allocated":

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-mn-app",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Create Midnight Network applications with zero configuration",
55
"main": "dist/index.js",
66
"bin": {

templates/hello-world/package.json.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"build": "tsc",
1414
"deploy": "node dist/deploy.js",
1515
"cli": "node dist/cli.js",
16+
"check-balance": "npm run build && node dist/check-balance.js",
1617
"reset": "rm -rf contracts/managed deployment.json dist && npm run compile",
1718
"validate": "tsc --noEmit && npm run compile",
1819
"clean": "rm -rf dist contracts/managed deployment.json",
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

templates/hello-world/src/deploy.ts.template

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ async function main() {
8484
let balance = state.balances[nativeToken()] || 0n;
8585

8686
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");
9199
console.log(`Waiting to receive tokens...`);
92100
balance = await waitForFunds(wallet);
93101
}

0 commit comments

Comments
 (0)