npubpayments/lnd-get-info.ts

41 lines
1004 B
TypeScript
Raw Permalink Normal View History

import { encodeHex } from "https://deno.land/std@0.224.0/encoding/hex.ts";
// Constants
const REST_HOST = '192.168.0.42:10010';
const MACAROON_PATH = 'assets/readonly.macaroon';
const TLS_PATH = 'assets/tls.cert';
const url = `https://${REST_HOST}/v1/getinfo`;
//const macaroonBytes = Deno.readTextFileSync(MACAROON_PATH);
//const macaroon = encodeHex(macaroonBytes).toString();
//console.log(macaroon);
using file = Deno.openSync(MACAROON_PATH, { read: true, write: false });
// Configure headers
const headers = new Headers({
'Grpc-Metadata-macaroon': macaroon,
});
// Function to make the GET request
async function getLndInfo() {
const response = await fetch(url, {
method: "GET",
headers: headers,
});
// Check if the response is OK
if (!response.ok) {
console.error("Failed to fetch:", response.status);
return;
}
// Parse the JSON response
const lndInfo = await response.json();
console.log(lndInfo);
}
// Execute the function
getLndInfo();
file.close();