-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (45 loc) · 1.82 KB
/
index.js
File metadata and controls
59 lines (45 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require("fs").promises;
const axios = require("axios");
const bitcoin = require("bitcoin-core");
async function callCln(method, params = {}) {
const response = await axios.post(
`http://localhost:3010/v1/${method}`,
params,
{ headers: { Rune: process.env.CLN_RUNE } },
);
return response.data;
}
async function main() {
// Example: Get blockchain info and lightning node info
const bitcoinClient = new bitcoin({
network: "regtest",
username: "alice",
password: "password",
port: 18443,
});
console.log("Bitcoin Node Info:", await bitcoinClient.getBlockchainInfo());
const lnInfo = await callCln("getinfo");
console.log("Lightning Node Info:", lnInfo);
// Create a new address for funding using lightning-cli and store it in CLN_ADDRESS
// Check if wallet exists, if not Create a bitcoin wallet named 'mining_wallet' using bitcoin-cli for mining
// Generate a new address and mine blocks to it. How many blocks need to mined? Why?
// Fund the Lightning node by sending 0.1 BTC from the mining wallet to CLN_ADDRESS
// Confirm the funding transaction by mining 6 blocks
// Verify Lightning wallet balance using lightning-cli listfunds
// Create an invoice with parameters and store the invoice string:
// - Amount: 50,000 satoshis (50000000 millisatoshis)
// - Label: Generate unique label using timestamp (e.g., "invoice_$(date +%s)")
// - Description: "Coffee Payment"
// - Expiry: 3600 seconds
// Decode the invoice string using lightning-cli decodepay and verify the parameters
// Output the invoice details in the specified format to out.txt
// - Payment hash
// - BOLT11 invoice string
// - Amount
// - Description
// - Expiry time
}
main().catch(err => {
console.error('Error:', err);
process.exit(1);
});