|
1 | 1 | // Import the library
|
2 |
| -// @chunk {"steps": ["import-node-tag"]} |
3 |
| -const xrpl = require("xrpl") |
4 |
| -// @chunk-end |
5 |
| - |
6 |
| -// Wrap code in an async function so we can use await |
7 |
| -async function main() { |
8 |
| - |
9 |
| - // @chunk {"steps": ["connect-tag"]} |
10 |
| - // Define the network client |
11 |
| - const SERVER_URL = "wss://s.altnet.rippletest.net:51233/" |
12 |
| - const client = new xrpl.Client(SERVER_URL) |
13 |
| - await client.connect() |
14 |
| - // @chunk-end |
| 2 | +// @chunk {"steps": ["connect-tag"]} |
| 3 | +import xrpl from "xrpl" |
15 | 4 |
|
16 |
| - // @chunk {"steps": ["get-account-create-wallet-tag"]} |
17 |
| - // Create a wallet and fund it with the Testnet faucet: |
18 |
| - const fund_result = await client.fundWallet() |
19 |
| - const test_wallet = fund_result.wallet |
20 |
| - console.log(fund_result) |
21 |
| - // @chunk-end |
| 5 | +// Define the network client |
| 6 | +const SERVER_URL = "wss://s.altnet.rippletest.net:51233/" |
| 7 | +const client = new xrpl.Client(SERVER_URL) |
| 8 | +await client.connect() |
| 9 | +// @chunk-end |
22 | 10 |
|
23 |
| - // To generate keys only, uncomment the code below |
24 |
| - // @chunk {"steps": ["get-account-create-wallet-b-tag"]} |
25 |
| - // const test_wallet = xrpl.Wallet.generate() |
26 |
| - // @chunk-end |
| 11 | +// @chunk {"steps": ["get-account-create-wallet-tag"]} |
| 12 | +// Create a wallet and fund it with the Testnet faucet: |
| 13 | +const fund_result = await client.fundWallet() |
| 14 | +const test_wallet = fund_result.wallet |
| 15 | +console.log(fund_result) |
| 16 | +// @chunk-end |
27 | 17 |
|
28 |
| - // To provide your own seed, replace the test_wallet value with the below |
29 |
| - // @chunk {"steps": ["get-account-create-wallet-c-tag"], "inputs": ["wallet-input"]} |
30 |
| - // const test_wallet = xrpl.Wallet.fromSeed({{wallet-input}}) |
31 |
| - // @chunk-end |
| 18 | +// To generate keys only, uncomment the code below |
| 19 | +// @chunk {"steps": ["get-account-create-wallet-b-tag"]} |
| 20 | +// const test_wallet = xrpl.Wallet.generate() |
| 21 | +// @chunk-end |
32 | 22 |
|
33 |
| - // @chunk {"steps": ["query-xrpl-tag"]} |
34 |
| - // Get info from the ledger about the address we just funded |
35 |
| - const response = await client.request({ |
36 |
| - "command": "account_info", |
37 |
| - "account": test_wallet.address, |
38 |
| - "ledger_index": "validated" |
39 |
| - }) |
40 |
| - console.log(response) |
41 |
| - // @chunk-end |
| 23 | +// To provide your own seed, replace the test_wallet value with the below |
| 24 | +// @chunk {"steps": ["get-account-create-wallet-c-tag"]} |
| 25 | +// const test_wallet = xrpl.Wallet.fromSeed("your-seed-key") |
| 26 | +// @chunk-end |
42 | 27 |
|
43 |
| - // @chunk {"steps": ["listen-for-events-tag"]} |
44 |
| - // Listen to ledger close events |
45 |
| - client.request({ |
46 |
| - "command": "subscribe", |
47 |
| - "streams": ["ledger"] |
48 |
| - }) |
49 |
| - client.on("ledgerClosed", async (ledger) => { |
50 |
| - console.log(`Ledger #${ledger.ledger_index} validated with ${ledger.txn_count} transactions!`) |
51 |
| - }) |
52 |
| - // @chunk-end |
| 28 | +// @chunk {"steps": ["query-xrpl-tag"]} |
| 29 | +// Get info from the ledger about the address we just funded |
| 30 | +const response = await client.request({ |
| 31 | + "command": "account_info", |
| 32 | + "account": test_wallet.address, |
| 33 | + "ledger_index": "validated" |
| 34 | +}) |
| 35 | +console.log(response) |
| 36 | +// @chunk-end |
53 | 37 |
|
54 |
| - // @chunk {"steps": ["disconnect-tag"]} |
55 |
| - // Disconnect when done so Node.js can end the process |
56 |
| - await client.disconnect() |
57 |
| - // @chunk-end |
58 |
| -} |
| 38 | +// @chunk {"steps": ["listen-for-events-tag"]} |
| 39 | +// Listen to ledger close events |
| 40 | +client.request({ |
| 41 | + "command": "subscribe", |
| 42 | + "streams": ["ledger"] |
| 43 | +}) |
| 44 | +client.on("ledgerClosed", async (ledger) => { |
| 45 | + console.log(`Ledger #${ledger.ledger_index} validated with ${ledger.txn_count} transactions!`) |
| 46 | +}) |
| 47 | +// @chunk-end |
59 | 48 |
|
60 |
| -// call the async function |
61 |
| -main() |
| 49 | +// @chunk {"steps": ["disconnect-node-tag"]} |
| 50 | +// Disconnect when done so Node.js can end the process |
| 51 | +await client.disconnect() |
| 52 | +// @chunk-end |
0 commit comments