forked from getAlby/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeysends.js
53 lines (45 loc) · 1.4 KB
/
keysends.js
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
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { auth, Client } from "../dist/index.module.js";
const rl = readline.createInterface({ input, output });
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
callback: "http://localhost:8080/callback",
scopes: [
"invoices:read",
"account:read",
"balance:read",
"invoices:create",
"invoices:read",
"payments:send",
],
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});
console.log(`Open the following URL and authenticate the app:`);
console.log(await authClient.generateAuthURL());
console.log("----\n");
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();
await authClient.requestAccessToken(code);
console.log(authClient.token);
const client = new Client(authClient);
const response = client.keysend([
{
amount: 10,
destination:
"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6",
customRecords: { 34349334: "I love amboss" },
},
{
amount: 11,
destination:
"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6",
customRecords: { 34349334: "I love amboss" },
},
]);
console.log(JSON.stringify(response));