-
Notifications
You must be signed in to change notification settings - Fork 1
/
quote-create-debit-amount.ts
54 lines (47 loc) · 1.51 KB
/
quote-create-debit-amount.ts
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
import dotenv from "dotenv";
import { join } from "path";
import { fileURLToPath } from "url";
dotenv.config({
path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
});
const KEY_ID = process.env.KEY_ID;
const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
//@! start chunk 1 | title=Import dependencies
import { createAuthenticatedClient } from "@interledger/open-payments";
//@! end chunk 1
//@! start chunk 2 | title=Initialize Open Payments client
const client = await createAuthenticatedClient({
walletAddressUrl: WALLET_ADDRESS,
privateKey: PRIVATE_KEY_PATH,
keyId: KEY_ID,
});
//@! end chunk 2
//@! start chunk 3 | title=Get wallet address information
const walletAddress = await client.walletAddress.get({
url: WALLET_ADDRESS,
});
//@! end chunk 3
//@! start chunk 4 | title=Create quote with debit amount
const quote = await client.quote.create(
{
url: new URL(WALLET_ADDRESS).origin,
accessToken: QUOTE_ACCESS_TOKEN,
},
{
method: "ilp",
walletAddress: WALLET_ADDRESS,
receiver: INCOMING_PAYMENT_URL,
debitAmount: {
value: "500",
assetCode: walletAddress.assetCode,
assetScale: walletAddress.assetScale,
},
},
);
//@! end chunk 4
//@! start chunk 5 | title=Output
console.log("QUOTE_URL =", quote.id);
//@! end chunk 5