dhali-js 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +27 -25
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,40 +16,42 @@ npm install dhali-js
16
16
  ## Quick Start
17
17
 
18
18
  ```js
19
- import { Wallet, Client } from 'xrpl'
20
- import {
21
- ChannelNotFound,
22
- DhaliChannelManager
23
- } from 'dhali-js'
19
+ const { Wallet } = require('xrpl')
20
+ const { DhaliChannelManager, ChannelNotFound } = require('dhali-js')
24
21
 
25
- // 1. Load your wallet from secret
26
- const seed = 'sXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
27
- const wallet = Wallet.fromSeed(seed)
22
+ const seed = "sXXX"
28
23
 
29
- // 2. Create the manager (connects automatically under the hood)
30
- const dhaliManager = new DhaliChannelManager(wallet)
31
-
32
- async function getPaymentClaim() {
24
+ ;(async () => {
25
+ const wallet = Wallet.fromSeed(seed)
26
+ const manager = new DhaliChannelManager(wallet)
27
+
28
+ let token
33
29
  try {
34
- // Get an auth token
35
- return await dhaliManager.getAuthToken()
30
+ token = await manager.getAuthToken()
36
31
  } catch (err) {
37
32
  if (err instanceof ChannelNotFound) {
38
- // If no channel exists, create one with 1 XRP (1 000 000 drops)
39
- await dhaliManager.deposit(1_000_000)
40
- return await dhaliManager.getAuthToken()
33
+ await manager.deposit(1_000_000)
34
+ token = await manager.getAuthToken()
35
+ } else {
36
+ console.error(err)
37
+ process.exit(1)
41
38
  }
42
- throw err
43
39
  }
44
- }
45
40
 
46
- ;(async () => {
47
- for (let i = 0; i < 2; i++) {
48
- const token = await getPaymentClaim()
49
- const url = `https://xrplcluster.dhali.io?payment-claim=${token}`
50
- // ... use token in your fetch/post to Dhali API ...
51
- }
41
+ const url = `https://xrplcluster.dhali.io?payment-claim=${token}`
42
+ const resp = await fetch(url, {
43
+ method: 'POST',
44
+ headers: { 'Content-Type': 'application/json' },
45
+ body: JSON.stringify({
46
+ method: 'account_info',
47
+ params: [{ account: wallet.classicAddress, ledger_index: 'validated' }],
48
+ id: 1,
49
+ }),
50
+ })
51
+ const result = await resp.json()
52
+ console.log(result)
52
53
  })()
54
+
53
55
  ```
54
56
 
55
57
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dhali-js",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A JavaScript library for managing XRPL payment channels and generating auth tokens for Dhali APIs",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",