xrpl 2.14.0 → 3.0.0-beta.1

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 (407) hide show
  1. package/README.md +2 -2
  2. package/build/xrpl-latest-min.js +1 -1
  3. package/build/xrpl-latest-min.js.map +1 -1
  4. package/build/xrpl-latest.js +15451 -74357
  5. package/build/xrpl-latest.js.map +1 -1
  6. package/dist/npm/Wallet/authorizeChannel.d.ts +3 -0
  7. package/dist/npm/Wallet/authorizeChannel.d.ts.map +1 -0
  8. package/dist/npm/Wallet/authorizeChannel.js +14 -0
  9. package/dist/npm/Wallet/authorizeChannel.js.map +1 -0
  10. package/dist/npm/Wallet/defaultFaucets.js +1 -1
  11. package/dist/npm/Wallet/defaultFaucets.js.map +1 -1
  12. package/dist/npm/Wallet/fundWallet.d.ts +17 -3
  13. package/dist/npm/Wallet/fundWallet.d.ts.map +1 -1
  14. package/dist/npm/Wallet/fundWallet.js +53 -78
  15. package/dist/npm/Wallet/fundWallet.js.map +1 -1
  16. package/dist/npm/Wallet/index.d.ts.map +1 -1
  17. package/dist/npm/Wallet/index.js +24 -23
  18. package/dist/npm/Wallet/index.js.map +1 -1
  19. package/dist/npm/Wallet/rfc1751.d.ts +1 -2
  20. package/dist/npm/Wallet/rfc1751.d.ts.map +1 -1
  21. package/dist/npm/Wallet/rfc1751.js +21 -5
  22. package/dist/npm/Wallet/rfc1751.js.map +1 -1
  23. package/dist/npm/Wallet/signer.d.ts +2 -4
  24. package/dist/npm/Wallet/signer.d.ts.map +1 -1
  25. package/dist/npm/Wallet/signer.js +19 -14
  26. package/dist/npm/Wallet/signer.js.map +1 -1
  27. package/dist/npm/Wallet/walletFromSecretNumbers.js +2 -2
  28. package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -1
  29. package/dist/npm/client/RequestManager.d.ts +3 -2
  30. package/dist/npm/client/RequestManager.d.ts.map +1 -1
  31. package/dist/npm/client/RequestManager.js +25 -1
  32. package/dist/npm/client/RequestManager.js.map +1 -1
  33. package/dist/npm/client/connection.d.ts +8 -11
  34. package/dist/npm/client/connection.d.ts.map +1 -1
  35. package/dist/npm/client/connection.js +11 -57
  36. package/dist/npm/client/connection.js.map +1 -1
  37. package/dist/npm/client/index.d.ts +56 -79
  38. package/dist/npm/client/index.d.ts.map +1 -1
  39. package/dist/npm/client/index.js +155 -42
  40. package/dist/npm/client/index.js.map +1 -1
  41. package/dist/npm/client/partialPayment.d.ts +4 -2
  42. package/dist/npm/client/partialPayment.d.ts.map +1 -1
  43. package/dist/npm/client/partialPayment.js.map +1 -1
  44. package/dist/npm/errors.d.ts.map +1 -1
  45. package/dist/npm/errors.js +1 -2
  46. package/dist/npm/errors.js.map +1 -1
  47. package/dist/npm/index.d.ts +1 -1
  48. package/dist/npm/index.d.ts.map +1 -1
  49. package/dist/npm/index.js +1 -3
  50. package/dist/npm/index.js.map +1 -1
  51. package/dist/npm/models/ledger/AccountRoot.js +1 -1
  52. package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
  53. package/dist/npm/models/ledger/Ledger.d.ts +2 -2
  54. package/dist/npm/models/ledger/Ledger.d.ts.map +1 -1
  55. package/dist/npm/models/ledger/Offer.js +1 -1
  56. package/dist/npm/models/ledger/Offer.js.map +1 -1
  57. package/dist/npm/models/ledger/RippleState.js +1 -1
  58. package/dist/npm/models/ledger/RippleState.js.map +1 -1
  59. package/dist/npm/models/ledger/SignerList.js +1 -1
  60. package/dist/npm/models/ledger/SignerList.js.map +1 -1
  61. package/dist/npm/models/methods/index.d.ts +12 -1
  62. package/dist/npm/models/methods/index.d.ts.map +1 -1
  63. package/dist/npm/models/methods/ledger.d.ts +35 -7
  64. package/dist/npm/models/methods/ledger.d.ts.map +1 -1
  65. package/dist/npm/models/methods/submit.d.ts +2 -2
  66. package/dist/npm/models/methods/submit.d.ts.map +1 -1
  67. package/dist/npm/models/methods/subscribe.d.ts +3 -0
  68. package/dist/npm/models/methods/subscribe.d.ts.map +1 -1
  69. package/dist/npm/models/methods/tx.d.ts +2 -3
  70. package/dist/npm/models/methods/tx.d.ts.map +1 -1
  71. package/dist/npm/models/transactions/AMMDeposit.js +1 -1
  72. package/dist/npm/models/transactions/AMMDeposit.js.map +1 -1
  73. package/dist/npm/models/transactions/AMMWithdraw.js +1 -1
  74. package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -1
  75. package/dist/npm/models/transactions/NFTokenAcceptOffer.d.ts +4 -0
  76. package/dist/npm/models/transactions/NFTokenAcceptOffer.d.ts.map +1 -1
  77. package/dist/npm/models/transactions/NFTokenAcceptOffer.js.map +1 -1
  78. package/dist/npm/models/transactions/NFTokenCancelOffer.d.ts +4 -0
  79. package/dist/npm/models/transactions/NFTokenCancelOffer.d.ts.map +1 -1
  80. package/dist/npm/models/transactions/NFTokenCancelOffer.js.map +1 -1
  81. package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts +4 -0
  82. package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
  83. package/dist/npm/models/transactions/NFTokenCreateOffer.js +1 -1
  84. package/dist/npm/models/transactions/NFTokenCreateOffer.js.map +1 -1
  85. package/dist/npm/models/transactions/NFTokenMint.d.ts +4 -0
  86. package/dist/npm/models/transactions/NFTokenMint.d.ts.map +1 -1
  87. package/dist/npm/models/transactions/NFTokenMint.js +1 -1
  88. package/dist/npm/models/transactions/NFTokenMint.js.map +1 -1
  89. package/dist/npm/models/transactions/XChainModifyBridge.js +1 -1
  90. package/dist/npm/models/transactions/XChainModifyBridge.js.map +1 -1
  91. package/dist/npm/models/transactions/accountSet.js +2 -2
  92. package/dist/npm/models/transactions/accountSet.js.map +1 -1
  93. package/dist/npm/models/transactions/enableAmendment.js +1 -1
  94. package/dist/npm/models/transactions/enableAmendment.js.map +1 -1
  95. package/dist/npm/models/transactions/index.d.ts +1 -1
  96. package/dist/npm/models/transactions/index.d.ts.map +1 -1
  97. package/dist/npm/models/transactions/index.js.map +1 -1
  98. package/dist/npm/models/transactions/metadata.d.ts +9 -1
  99. package/dist/npm/models/transactions/metadata.d.ts.map +1 -1
  100. package/dist/npm/models/transactions/metadata.js.map +1 -1
  101. package/dist/npm/models/transactions/offerCreate.js +1 -1
  102. package/dist/npm/models/transactions/offerCreate.js.map +1 -1
  103. package/dist/npm/models/transactions/payment.d.ts +5 -0
  104. package/dist/npm/models/transactions/payment.d.ts.map +1 -1
  105. package/dist/npm/models/transactions/payment.js +1 -1
  106. package/dist/npm/models/transactions/payment.js.map +1 -1
  107. package/dist/npm/models/transactions/paymentChannelClaim.js +1 -1
  108. package/dist/npm/models/transactions/paymentChannelClaim.js.map +1 -1
  109. package/dist/npm/models/transactions/transaction.d.ts +6 -4
  110. package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
  111. package/dist/npm/models/transactions/transaction.js.map +1 -1
  112. package/dist/npm/models/transactions/trustSet.js +1 -1
  113. package/dist/npm/models/transactions/trustSet.js.map +1 -1
  114. package/dist/npm/snippets/src/bridgeTransfer.js +2 -2
  115. package/dist/npm/snippets/src/bridgeTransfer.js.map +1 -1
  116. package/dist/npm/snippets/src/getTransaction.js +1 -1
  117. package/dist/npm/snippets/src/getTransaction.js.map +1 -1
  118. package/dist/npm/snippets/src/paths.js +2 -3
  119. package/dist/npm/snippets/src/paths.js.map +1 -1
  120. package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
  121. package/dist/npm/src/Wallet/authorizeChannel.d.ts +3 -0
  122. package/dist/npm/src/Wallet/authorizeChannel.d.ts.map +1 -0
  123. package/dist/npm/src/Wallet/authorizeChannel.js +14 -0
  124. package/dist/npm/src/Wallet/authorizeChannel.js.map +1 -0
  125. package/dist/npm/src/Wallet/defaultFaucets.js +1 -1
  126. package/dist/npm/src/Wallet/defaultFaucets.js.map +1 -1
  127. package/dist/npm/src/Wallet/fundWallet.d.ts +17 -3
  128. package/dist/npm/src/Wallet/fundWallet.d.ts.map +1 -1
  129. package/dist/npm/src/Wallet/fundWallet.js +53 -78
  130. package/dist/npm/src/Wallet/fundWallet.js.map +1 -1
  131. package/dist/npm/src/Wallet/index.d.ts.map +1 -1
  132. package/dist/npm/src/Wallet/index.js +24 -23
  133. package/dist/npm/src/Wallet/index.js.map +1 -1
  134. package/dist/npm/src/Wallet/rfc1751.d.ts +1 -2
  135. package/dist/npm/src/Wallet/rfc1751.d.ts.map +1 -1
  136. package/dist/npm/src/Wallet/rfc1751.js +21 -5
  137. package/dist/npm/src/Wallet/rfc1751.js.map +1 -1
  138. package/dist/npm/src/Wallet/signer.d.ts +2 -4
  139. package/dist/npm/src/Wallet/signer.d.ts.map +1 -1
  140. package/dist/npm/src/Wallet/signer.js +19 -14
  141. package/dist/npm/src/Wallet/signer.js.map +1 -1
  142. package/dist/npm/src/Wallet/walletFromSecretNumbers.js +2 -2
  143. package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -1
  144. package/dist/npm/src/client/RequestManager.d.ts +3 -2
  145. package/dist/npm/src/client/RequestManager.d.ts.map +1 -1
  146. package/dist/npm/src/client/RequestManager.js +25 -1
  147. package/dist/npm/src/client/RequestManager.js.map +1 -1
  148. package/dist/npm/src/client/connection.d.ts +8 -11
  149. package/dist/npm/src/client/connection.d.ts.map +1 -1
  150. package/dist/npm/src/client/connection.js +11 -57
  151. package/dist/npm/src/client/connection.js.map +1 -1
  152. package/dist/npm/src/client/index.d.ts +56 -79
  153. package/dist/npm/src/client/index.d.ts.map +1 -1
  154. package/dist/npm/src/client/index.js +155 -42
  155. package/dist/npm/src/client/index.js.map +1 -1
  156. package/dist/npm/src/client/partialPayment.d.ts +4 -2
  157. package/dist/npm/src/client/partialPayment.d.ts.map +1 -1
  158. package/dist/npm/src/client/partialPayment.js.map +1 -1
  159. package/dist/npm/src/errors.d.ts.map +1 -1
  160. package/dist/npm/src/errors.js +1 -2
  161. package/dist/npm/src/errors.js.map +1 -1
  162. package/dist/npm/src/index.d.ts +1 -1
  163. package/dist/npm/src/index.d.ts.map +1 -1
  164. package/dist/npm/src/index.js +1 -3
  165. package/dist/npm/src/index.js.map +1 -1
  166. package/dist/npm/src/models/ledger/AccountRoot.js +1 -1
  167. package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
  168. package/dist/npm/src/models/ledger/Ledger.d.ts +2 -2
  169. package/dist/npm/src/models/ledger/Ledger.d.ts.map +1 -1
  170. package/dist/npm/src/models/ledger/Offer.js +1 -1
  171. package/dist/npm/src/models/ledger/Offer.js.map +1 -1
  172. package/dist/npm/src/models/ledger/RippleState.js +1 -1
  173. package/dist/npm/src/models/ledger/RippleState.js.map +1 -1
  174. package/dist/npm/src/models/ledger/SignerList.js +1 -1
  175. package/dist/npm/src/models/ledger/SignerList.js.map +1 -1
  176. package/dist/npm/src/models/methods/index.d.ts +12 -1
  177. package/dist/npm/src/models/methods/index.d.ts.map +1 -1
  178. package/dist/npm/src/models/methods/ledger.d.ts +35 -7
  179. package/dist/npm/src/models/methods/ledger.d.ts.map +1 -1
  180. package/dist/npm/src/models/methods/submit.d.ts +2 -2
  181. package/dist/npm/src/models/methods/submit.d.ts.map +1 -1
  182. package/dist/npm/src/models/methods/subscribe.d.ts +3 -0
  183. package/dist/npm/src/models/methods/subscribe.d.ts.map +1 -1
  184. package/dist/npm/src/models/methods/tx.d.ts +2 -3
  185. package/dist/npm/src/models/methods/tx.d.ts.map +1 -1
  186. package/dist/npm/src/models/transactions/AMMDeposit.js +1 -1
  187. package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -1
  188. package/dist/npm/src/models/transactions/AMMWithdraw.js +1 -1
  189. package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -1
  190. package/dist/npm/src/models/transactions/NFTokenAcceptOffer.d.ts +4 -0
  191. package/dist/npm/src/models/transactions/NFTokenAcceptOffer.d.ts.map +1 -1
  192. package/dist/npm/src/models/transactions/NFTokenAcceptOffer.js.map +1 -1
  193. package/dist/npm/src/models/transactions/NFTokenCancelOffer.d.ts +4 -0
  194. package/dist/npm/src/models/transactions/NFTokenCancelOffer.d.ts.map +1 -1
  195. package/dist/npm/src/models/transactions/NFTokenCancelOffer.js.map +1 -1
  196. package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts +4 -0
  197. package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
  198. package/dist/npm/src/models/transactions/NFTokenCreateOffer.js +1 -1
  199. package/dist/npm/src/models/transactions/NFTokenCreateOffer.js.map +1 -1
  200. package/dist/npm/src/models/transactions/NFTokenMint.d.ts +4 -0
  201. package/dist/npm/src/models/transactions/NFTokenMint.d.ts.map +1 -1
  202. package/dist/npm/src/models/transactions/NFTokenMint.js +1 -1
  203. package/dist/npm/src/models/transactions/NFTokenMint.js.map +1 -1
  204. package/dist/npm/src/models/transactions/XChainModifyBridge.js +1 -1
  205. package/dist/npm/src/models/transactions/XChainModifyBridge.js.map +1 -1
  206. package/dist/npm/src/models/transactions/accountSet.js +2 -2
  207. package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
  208. package/dist/npm/src/models/transactions/enableAmendment.js +1 -1
  209. package/dist/npm/src/models/transactions/enableAmendment.js.map +1 -1
  210. package/dist/npm/src/models/transactions/index.d.ts +1 -1
  211. package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
  212. package/dist/npm/src/models/transactions/index.js.map +1 -1
  213. package/dist/npm/src/models/transactions/metadata.d.ts +9 -1
  214. package/dist/npm/src/models/transactions/metadata.d.ts.map +1 -1
  215. package/dist/npm/src/models/transactions/metadata.js.map +1 -1
  216. package/dist/npm/src/models/transactions/offerCreate.js +1 -1
  217. package/dist/npm/src/models/transactions/offerCreate.js.map +1 -1
  218. package/dist/npm/src/models/transactions/payment.d.ts +5 -0
  219. package/dist/npm/src/models/transactions/payment.d.ts.map +1 -1
  220. package/dist/npm/src/models/transactions/payment.js +1 -1
  221. package/dist/npm/src/models/transactions/payment.js.map +1 -1
  222. package/dist/npm/src/models/transactions/paymentChannelClaim.js +1 -1
  223. package/dist/npm/src/models/transactions/paymentChannelClaim.js.map +1 -1
  224. package/dist/npm/src/models/transactions/transaction.d.ts +6 -4
  225. package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
  226. package/dist/npm/src/models/transactions/transaction.js.map +1 -1
  227. package/dist/npm/src/models/transactions/trustSet.js +1 -1
  228. package/dist/npm/src/models/transactions/trustSet.js.map +1 -1
  229. package/dist/npm/src/sugar/autofill.d.ts +6 -2
  230. package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
  231. package/dist/npm/src/sugar/autofill.js +9 -28
  232. package/dist/npm/src/sugar/autofill.js.map +1 -1
  233. package/dist/npm/src/sugar/balances.d.ts +2 -17
  234. package/dist/npm/src/sugar/balances.d.ts.map +1 -1
  235. package/dist/npm/src/sugar/balances.js +2 -60
  236. package/dist/npm/src/sugar/balances.js.map +1 -1
  237. package/dist/npm/src/sugar/getOrderbook.d.ts +19 -5
  238. package/dist/npm/src/sugar/getOrderbook.d.ts.map +1 -1
  239. package/dist/npm/src/sugar/getOrderbook.js +72 -53
  240. package/dist/npm/src/sugar/getOrderbook.js.map +1 -1
  241. package/dist/npm/src/sugar/index.d.ts +0 -4
  242. package/dist/npm/src/sugar/index.d.ts.map +1 -1
  243. package/dist/npm/src/sugar/index.js +0 -13
  244. package/dist/npm/src/sugar/index.js.map +1 -1
  245. package/dist/npm/src/sugar/submit.d.ts +7 -11
  246. package/dist/npm/src/sugar/submit.d.ts.map +1 -1
  247. package/dist/npm/src/sugar/submit.js +5 -22
  248. package/dist/npm/src/sugar/submit.js.map +1 -1
  249. package/dist/npm/src/utils/collections.d.ts +5 -0
  250. package/dist/npm/src/utils/collections.d.ts.map +1 -0
  251. package/dist/npm/src/utils/collections.js +24 -0
  252. package/dist/npm/src/utils/collections.js.map +1 -0
  253. package/dist/npm/src/utils/getBalanceChanges.d.ts.map +1 -1
  254. package/dist/npm/src/utils/getBalanceChanges.js +3 -4
  255. package/dist/npm/src/utils/getBalanceChanges.js.map +1 -1
  256. package/dist/npm/src/utils/getNFTokenID.d.ts.map +1 -1
  257. package/dist/npm/src/utils/getNFTokenID.js +8 -8
  258. package/dist/npm/src/utils/getNFTokenID.js.map +1 -1
  259. package/dist/npm/src/utils/hashes/SHAMap/node.js +1 -1
  260. package/dist/npm/src/utils/hashes/SHAMap/node.js.map +1 -1
  261. package/dist/npm/src/utils/hashes/hashLedger.d.ts +1 -2
  262. package/dist/npm/src/utils/hashes/hashLedger.d.ts.map +1 -1
  263. package/dist/npm/src/utils/hashes/hashLedger.js +7 -7
  264. package/dist/npm/src/utils/hashes/hashLedger.js.map +1 -1
  265. package/dist/npm/src/utils/hashes/index.d.ts.map +1 -1
  266. package/dist/npm/src/utils/hashes/index.js +3 -2
  267. package/dist/npm/src/utils/hashes/index.js.map +1 -1
  268. package/dist/npm/src/utils/hashes/sha512Half.d.ts.map +1 -1
  269. package/dist/npm/src/utils/hashes/sha512Half.js +4 -7
  270. package/dist/npm/src/utils/hashes/sha512Half.js.map +1 -1
  271. package/dist/npm/src/utils/index.d.ts.map +1 -1
  272. package/dist/npm/src/utils/index.js +6 -29
  273. package/dist/npm/src/utils/index.js.map +1 -1
  274. package/dist/npm/src/utils/parseNFTokenID.d.ts.map +1 -1
  275. package/dist/npm/src/utils/parseNFTokenID.js +2 -1
  276. package/dist/npm/src/utils/parseNFTokenID.js.map +1 -1
  277. package/dist/npm/src/utils/stringConversion.d.ts +1 -2
  278. package/dist/npm/src/utils/stringConversion.d.ts.map +1 -1
  279. package/dist/npm/src/utils/stringConversion.js +3 -2
  280. package/dist/npm/src/utils/stringConversion.js.map +1 -1
  281. package/dist/npm/src/utils/xrpConversion.d.ts +1 -1
  282. package/dist/npm/src/utils/xrpConversion.js +1 -1
  283. package/dist/npm/src/utils/xrpConversion.js.map +1 -1
  284. package/dist/npm/sugar/autofill.d.ts +6 -2
  285. package/dist/npm/sugar/autofill.d.ts.map +1 -1
  286. package/dist/npm/sugar/autofill.js +9 -28
  287. package/dist/npm/sugar/autofill.js.map +1 -1
  288. package/dist/npm/sugar/balances.d.ts +2 -17
  289. package/dist/npm/sugar/balances.d.ts.map +1 -1
  290. package/dist/npm/sugar/balances.js +2 -60
  291. package/dist/npm/sugar/balances.js.map +1 -1
  292. package/dist/npm/sugar/getOrderbook.d.ts +19 -5
  293. package/dist/npm/sugar/getOrderbook.d.ts.map +1 -1
  294. package/dist/npm/sugar/getOrderbook.js +72 -53
  295. package/dist/npm/sugar/getOrderbook.js.map +1 -1
  296. package/dist/npm/sugar/index.d.ts +0 -4
  297. package/dist/npm/sugar/index.d.ts.map +1 -1
  298. package/dist/npm/sugar/index.js +0 -13
  299. package/dist/npm/sugar/index.js.map +1 -1
  300. package/dist/npm/sugar/submit.d.ts +7 -11
  301. package/dist/npm/sugar/submit.d.ts.map +1 -1
  302. package/dist/npm/sugar/submit.js +5 -22
  303. package/dist/npm/sugar/submit.js.map +1 -1
  304. package/dist/npm/utils/collections.d.ts +5 -0
  305. package/dist/npm/utils/collections.d.ts.map +1 -0
  306. package/dist/npm/utils/collections.js +24 -0
  307. package/dist/npm/utils/collections.js.map +1 -0
  308. package/dist/npm/utils/getBalanceChanges.d.ts.map +1 -1
  309. package/dist/npm/utils/getBalanceChanges.js +3 -4
  310. package/dist/npm/utils/getBalanceChanges.js.map +1 -1
  311. package/dist/npm/utils/getNFTokenID.d.ts.map +1 -1
  312. package/dist/npm/utils/getNFTokenID.js +8 -8
  313. package/dist/npm/utils/getNFTokenID.js.map +1 -1
  314. package/dist/npm/utils/hashes/SHAMap/node.js +1 -1
  315. package/dist/npm/utils/hashes/SHAMap/node.js.map +1 -1
  316. package/dist/npm/utils/hashes/hashLedger.d.ts +1 -2
  317. package/dist/npm/utils/hashes/hashLedger.d.ts.map +1 -1
  318. package/dist/npm/utils/hashes/hashLedger.js +7 -7
  319. package/dist/npm/utils/hashes/hashLedger.js.map +1 -1
  320. package/dist/npm/utils/hashes/index.d.ts.map +1 -1
  321. package/dist/npm/utils/hashes/index.js +3 -2
  322. package/dist/npm/utils/hashes/index.js.map +1 -1
  323. package/dist/npm/utils/hashes/sha512Half.d.ts.map +1 -1
  324. package/dist/npm/utils/hashes/sha512Half.js +4 -7
  325. package/dist/npm/utils/hashes/sha512Half.js.map +1 -1
  326. package/dist/npm/utils/index.d.ts.map +1 -1
  327. package/dist/npm/utils/index.js +6 -29
  328. package/dist/npm/utils/index.js.map +1 -1
  329. package/dist/npm/utils/parseNFTokenID.d.ts.map +1 -1
  330. package/dist/npm/utils/parseNFTokenID.js +2 -1
  331. package/dist/npm/utils/parseNFTokenID.js.map +1 -1
  332. package/dist/npm/utils/stringConversion.d.ts +1 -2
  333. package/dist/npm/utils/stringConversion.d.ts.map +1 -1
  334. package/dist/npm/utils/stringConversion.js +3 -2
  335. package/dist/npm/utils/stringConversion.js.map +1 -1
  336. package/dist/npm/utils/xrpConversion.d.ts +1 -1
  337. package/dist/npm/utils/xrpConversion.js +1 -1
  338. package/dist/npm/utils/xrpConversion.js.map +1 -1
  339. package/package.json +23 -25
  340. package/src/Wallet/authorizeChannel.ts +26 -0
  341. package/src/Wallet/fundWallet.ts +153 -214
  342. package/src/Wallet/index.ts +28 -25
  343. package/src/Wallet/rfc1751.ts +45 -16
  344. package/src/Wallet/signer.ts +34 -44
  345. package/src/Wallet/walletFromSecretNumbers.ts +1 -1
  346. package/src/client/RequestManager.ts +40 -14
  347. package/src/client/connection.ts +26 -93
  348. package/src/client/index.ts +706 -274
  349. package/src/client/partialPayment.ts +16 -14
  350. package/src/errors.ts +1 -3
  351. package/src/index.ts +1 -3
  352. package/src/models/ledger/Ledger.ts +3 -9
  353. package/src/models/methods/index.ts +177 -0
  354. package/src/models/methods/ledger.ts +149 -20
  355. package/src/models/methods/submit.ts +2 -2
  356. package/src/models/methods/subscribe.ts +36 -0
  357. package/src/models/methods/tx.ts +3 -5
  358. package/src/models/transactions/NFTokenAcceptOffer.ts +6 -0
  359. package/src/models/transactions/NFTokenCancelOffer.ts +6 -0
  360. package/src/models/transactions/NFTokenCreateOffer.ts +6 -0
  361. package/src/models/transactions/NFTokenMint.ts +6 -0
  362. package/src/models/transactions/index.ts +1 -0
  363. package/src/models/transactions/metadata.ts +31 -1
  364. package/src/models/transactions/payment.ts +6 -0
  365. package/src/models/transactions/transaction.ts +21 -5
  366. package/src/sugar/autofill.ts +84 -88
  367. package/src/sugar/balances.ts +8 -116
  368. package/src/sugar/getOrderbook.ts +138 -61
  369. package/src/sugar/index.ts +0 -8
  370. package/src/sugar/submit.ts +128 -140
  371. package/src/utils/collections.ts +57 -0
  372. package/src/utils/getBalanceChanges.ts +2 -3
  373. package/src/utils/getNFTokenID.ts +18 -16
  374. package/src/utils/hashes/hashLedger.ts +7 -9
  375. package/src/utils/hashes/index.ts +3 -2
  376. package/src/utils/hashes/sha512Half.ts +4 -7
  377. package/src/utils/index.ts +12 -6
  378. package/src/utils/parseNFTokenID.ts +2 -1
  379. package/src/utils/stringConversion.ts +11 -6
  380. package/src/utils/xrpConversion.ts +2 -2
  381. package/dist/npm/client/BroadcastClient.d.ts +0 -7
  382. package/dist/npm/client/BroadcastClient.d.ts.map +0 -1
  383. package/dist/npm/client/BroadcastClient.js +0 -49
  384. package/dist/npm/client/BroadcastClient.js.map +0 -1
  385. package/dist/npm/client/WSWrapper.d.ts +0 -25
  386. package/dist/npm/client/WSWrapper.d.ts.map +0 -1
  387. package/dist/npm/client/WSWrapper.js +0 -44
  388. package/dist/npm/client/WSWrapper.js.map +0 -1
  389. package/dist/npm/src/client/BroadcastClient.d.ts +0 -7
  390. package/dist/npm/src/client/BroadcastClient.d.ts.map +0 -1
  391. package/dist/npm/src/client/BroadcastClient.js +0 -49
  392. package/dist/npm/src/client/BroadcastClient.js.map +0 -1
  393. package/dist/npm/src/client/WSWrapper.d.ts +0 -25
  394. package/dist/npm/src/client/WSWrapper.d.ts.map +0 -1
  395. package/dist/npm/src/client/WSWrapper.js +0 -44
  396. package/dist/npm/src/client/WSWrapper.js.map +0 -1
  397. package/dist/npm/src/sugar/getLedgerIndex.d.ts +0 -3
  398. package/dist/npm/src/sugar/getLedgerIndex.d.ts.map +0 -1
  399. package/dist/npm/src/sugar/getLedgerIndex.js +0 -22
  400. package/dist/npm/src/sugar/getLedgerIndex.js.map +0 -1
  401. package/dist/npm/sugar/getLedgerIndex.d.ts +0 -3
  402. package/dist/npm/sugar/getLedgerIndex.d.ts.map +0 -1
  403. package/dist/npm/sugar/getLedgerIndex.js +0 -22
  404. package/dist/npm/sugar/getLedgerIndex.js.map +0 -1
  405. package/src/client/BroadcastClient.ts +0 -84
  406. package/src/client/WSWrapper.ts +0 -106
  407. package/src/sugar/getLedgerIndex.ts +0 -15
@@ -1,118 +1,81 @@
1
1
  /* eslint-disable jsdoc/require-jsdoc -- Request has many aliases, but they don't need unique docs */
2
- /* eslint-disable @typescript-eslint/member-ordering -- TODO: remove when instance methods aren't members */
2
+
3
3
  /* eslint-disable max-lines -- Client is a large file w/ lots of imports/exports */
4
- import * as assert from 'assert'
5
- import { EventEmitter } from 'events'
4
+ import { EventEmitter } from 'eventemitter3'
6
5
 
7
- import { NotFoundError, ValidationError, XrplError } from '../errors'
6
+ import {
7
+ RippledError,
8
+ NotFoundError,
9
+ ValidationError,
10
+ XrplError,
11
+ } from '../errors'
12
+ import type { LedgerIndex, Balance } from '../models/common'
8
13
  import {
9
14
  Request,
10
- Response,
11
15
  // account methods
12
16
  AccountChannelsRequest,
13
17
  AccountChannelsResponse,
14
- AccountCurrenciesRequest,
15
- AccountCurrenciesResponse,
16
18
  AccountInfoRequest,
17
- AccountInfoResponse,
18
19
  AccountLinesRequest,
19
20
  AccountLinesResponse,
20
- AccountNFTsRequest,
21
- AccountNFTsResponse,
22
21
  AccountObjectsRequest,
23
22
  AccountObjectsResponse,
24
23
  AccountOffersRequest,
25
24
  AccountOffersResponse,
26
25
  AccountTxRequest,
27
26
  AccountTxResponse,
28
- GatewayBalancesRequest,
29
- GatewayBalancesResponse,
30
- NoRippleCheckRequest,
31
- NoRippleCheckResponse,
32
27
  // ledger methods
33
- LedgerRequest,
34
- LedgerResponse,
35
- LedgerClosedRequest,
36
- LedgerClosedResponse,
37
- LedgerCurrentRequest,
38
- LedgerCurrentResponse,
39
28
  LedgerDataRequest,
40
29
  LedgerDataResponse,
41
- LedgerEntryRequest,
42
- LedgerEntryResponse,
43
- // transaction methods
44
- SubmitRequest,
45
- SubmitResponse,
46
- SubmitMultisignedRequest,
47
- SubmitMultisignedResponse,
48
- TransactionEntryRequest,
49
- TransactionEntryResponse,
50
- TxRequest,
51
30
  TxResponse,
52
- // path and order book methods
53
- BookOffersRequest,
54
- BookOffersResponse,
55
- DepositAuthorizedRequest,
56
- DepositAuthorizedResponse,
57
- PathFindRequest,
58
- PathFindResponse,
59
- RipplePathFindRequest,
60
- RipplePathFindResponse,
61
- // payment channel methods
62
- ChannelVerifyRequest,
63
- ChannelVerifyResponse,
64
- // server info methods
65
- FeeRequest,
66
- FeeResponse,
67
- ManifestRequest,
68
- ManifestResponse,
69
- ServerInfoRequest,
70
- ServerInfoResponse,
71
- ServerStateRequest,
72
- ServerStateResponse,
73
- // utility methods
74
- PingRequest,
75
- PingResponse,
76
- RandomRequest,
77
- RandomResponse,
78
- LedgerStream,
79
- ValidationStream,
80
- TransactionStream,
81
- PathFindStream,
82
- PeerStatusStream,
83
- ConsensusStream,
84
- SubscribeRequest,
85
- SubscribeResponse,
86
- UnsubscribeRequest,
87
- UnsubscribeResponse,
88
- // NFT methods
89
- NFTBuyOffersRequest,
90
- NFTBuyOffersResponse,
91
- NFTSellOffersRequest,
92
- NFTSellOffersResponse,
93
- // clio only methods
94
- NFTInfoRequest,
95
- NFTInfoResponse,
96
- NFTHistoryRequest,
97
- NFTHistoryResponse,
98
- // AMM methods
99
- AMMInfoRequest,
100
- AMMInfoResponse,
101
- ServerDefinitionsRequest,
102
- ServerDefinitionsResponse,
103
31
  } from '../models/methods'
104
- import { BaseRequest, BaseResponse } from '../models/methods/baseMethod'
32
+ import type {
33
+ RequestResponseMap,
34
+ RequestAllResponseMap,
35
+ MarkerRequest,
36
+ MarkerResponse,
37
+ SubmitResponse,
38
+ } from '../models/methods'
39
+ import type { BookOffer, BookOfferCurrency } from '../models/methods/bookOffers'
40
+ import type {
41
+ EventTypes,
42
+ OnEventToListenerMap,
43
+ } from '../models/methods/subscribe'
44
+ import type { SubmittableTransaction } from '../models/transactions'
45
+ import { setTransactionFlagsToNumber } from '../models/utils/flags'
105
46
  import {
106
- autofill,
107
47
  ensureClassicAddress,
108
- getLedgerIndex,
109
- getOrderbook,
110
- getBalances,
111
- getXrpBalance,
112
- submit,
113
- submitAndWait,
48
+ submitRequest,
49
+ getSignedTx,
50
+ getLastLedgerSequence,
51
+ waitForFinalTransactionOutcome,
114
52
  } from '../sugar'
115
- import fundWallet from '../Wallet/fundWallet'
53
+ import {
54
+ setValidAddresses,
55
+ setNextValidSequenceNumber,
56
+ calculateFeePerTransactionType,
57
+ setLatestValidatedLedgerSequence,
58
+ checkAccountDeleteBlockers,
59
+ txNeedsNetworkID,
60
+ } from '../sugar/autofill'
61
+ import { formatBalances } from '../sugar/balances'
62
+ import {
63
+ validateOrderbookOptions,
64
+ createBookOffersRequest,
65
+ requestAllOffers,
66
+ reverseRequest,
67
+ extractOffers,
68
+ combineOrders,
69
+ separateBuySellOrders,
70
+ sortAndLimitOffers,
71
+ } from '../sugar/getOrderbook'
72
+ import { dropsToXrp, hashes, isValidClassicAddress } from '../utils'
73
+ import { Wallet } from '../Wallet'
74
+ import {
75
+ type FaucetRequestBody,
76
+ FundingOptions,
77
+ requestFunding,
78
+ } from '../Wallet/fundWallet'
116
79
 
117
80
  import {
118
81
  Connection,
@@ -127,10 +90,32 @@ import {
127
90
  export interface ClientOptions extends ConnectionUserOptions {
128
91
  feeCushion?: number
129
92
  maxFeeXRP?: string
130
- proxy?: string
131
93
  timeout?: number
132
94
  }
133
95
 
96
+ // Make sure to update both this and `RequestNextPageReturnMap` at the same time
97
+ type RequestNextPageType =
98
+ | AccountChannelsRequest
99
+ | AccountLinesRequest
100
+ | AccountObjectsRequest
101
+ | AccountOffersRequest
102
+ | AccountTxRequest
103
+ | LedgerDataRequest
104
+
105
+ type RequestNextPageReturnMap<T> = T extends AccountChannelsRequest
106
+ ? AccountChannelsResponse
107
+ : T extends AccountLinesRequest
108
+ ? AccountLinesResponse
109
+ : T extends AccountObjectsRequest
110
+ ? AccountObjectsResponse
111
+ : T extends AccountOffersRequest
112
+ ? AccountOffersResponse
113
+ : T extends AccountTxRequest
114
+ ? AccountTxResponse
115
+ : T extends LedgerDataRequest
116
+ ? LedgerDataResponse
117
+ : never
118
+
134
119
  /**
135
120
  * Get the response key / property name that contains the listed data for a
136
121
  * command. This varies from command to command, but we need to know it to
@@ -160,19 +145,10 @@ function getCollectKeyFromCommand(command: string): string | null {
160
145
  }
161
146
 
162
147
  function clamp(value: number, min: number, max: number): number {
163
- assert.ok(min <= max, 'Illegal clamp bounds')
164
- return Math.min(Math.max(value, min), max)
165
- }
166
-
167
- interface MarkerRequest extends BaseRequest {
168
- limit?: number
169
- marker?: unknown
170
- }
171
-
172
- interface MarkerResponse extends BaseResponse {
173
- result: {
174
- marker?: unknown
148
+ if (min > max) {
149
+ throw new Error('Illegal clamp bounds')
175
150
  }
151
+ return Math.min(Math.max(value, min), max)
176
152
  }
177
153
 
178
154
  const DEFAULT_FEE_CUSHION = 1.2
@@ -188,7 +164,7 @@ const NORMAL_DISCONNECT_CODE = 1000
188
164
  *
189
165
  * @category Clients
190
166
  */
191
- class Client extends EventEmitter {
167
+ class Client extends EventEmitter<EventTypes> {
192
168
  /*
193
169
  * Underlying connection to rippled.
194
170
  */
@@ -228,6 +204,12 @@ class Client extends EventEmitter {
228
204
  * @param server - URL of the server to connect to.
229
205
  * @param options - Options for client settings.
230
206
  * @category Constructor
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * import { Client } from "xrpl"
211
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
212
+ * ```
231
213
  */
232
214
  // eslint-disable-next-line max-lines-per-function -- okay because we have to set up all the connection handlers
233
215
  public constructor(server: string, options: ClientOptions = {}) {
@@ -304,87 +286,34 @@ class Client extends EventEmitter {
304
286
  return this.connection.getUrl()
305
287
  }
306
288
 
307
- /**
308
- * @category Network
309
- */
310
- public async request(
311
- r: AccountChannelsRequest,
312
- ): Promise<AccountChannelsResponse>
313
- public async request(
314
- r: AccountCurrenciesRequest,
315
- ): Promise<AccountCurrenciesResponse>
316
- public async request(r: AccountInfoRequest): Promise<AccountInfoResponse>
317
- public async request(r: AccountLinesRequest): Promise<AccountLinesResponse>
318
- public async request(r: AccountNFTsRequest): Promise<AccountNFTsResponse>
319
- public async request(
320
- r: AccountObjectsRequest,
321
- ): Promise<AccountObjectsResponse>
322
- public async request(r: AccountOffersRequest): Promise<AccountOffersResponse>
323
- public async request(r: AccountTxRequest): Promise<AccountTxResponse>
324
- public async request(r: AMMInfoRequest): Promise<AMMInfoResponse>
325
- public async request(r: BookOffersRequest): Promise<BookOffersResponse>
326
- public async request(r: ChannelVerifyRequest): Promise<ChannelVerifyResponse>
327
- public async request(
328
- r: DepositAuthorizedRequest,
329
- ): Promise<DepositAuthorizedResponse>
330
- public async request(r: FeeRequest): Promise<FeeResponse>
331
- public async request(
332
- r: GatewayBalancesRequest,
333
- ): Promise<GatewayBalancesResponse>
334
- public async request(r: LedgerRequest): Promise<LedgerResponse>
335
- public async request(r: LedgerClosedRequest): Promise<LedgerClosedResponse>
336
- public async request(r: LedgerCurrentRequest): Promise<LedgerCurrentResponse>
337
- public async request(r: LedgerDataRequest): Promise<LedgerDataResponse>
338
- public async request(r: LedgerEntryRequest): Promise<LedgerEntryResponse>
339
- public async request(r: ManifestRequest): Promise<ManifestResponse>
340
- public async request(r: NFTBuyOffersRequest): Promise<NFTBuyOffersResponse>
341
- public async request(r: NFTSellOffersRequest): Promise<NFTSellOffersResponse>
342
- public async request(r: NFTInfoRequest): Promise<NFTInfoResponse>
343
- public async request(r: NFTHistoryRequest): Promise<NFTHistoryResponse>
344
- public async request(r: NoRippleCheckRequest): Promise<NoRippleCheckResponse>
345
- public async request(r: PathFindRequest): Promise<PathFindResponse>
346
- public async request(r: PingRequest): Promise<PingResponse>
347
- public async request(r: RandomRequest): Promise<RandomResponse>
348
- public async request(
349
- r: RipplePathFindRequest,
350
- ): Promise<RipplePathFindResponse>
351
- public async request(
352
- r: ServerDefinitionsRequest,
353
- ): Promise<ServerDefinitionsResponse>
354
- public async request(r: ServerInfoRequest): Promise<ServerInfoResponse>
355
- public async request(r: ServerStateRequest): Promise<ServerStateResponse>
356
- public async request(r: SubmitRequest): Promise<SubmitResponse>
357
- public async request(
358
- r: SubmitMultisignedRequest,
359
- ): Promise<SubmitMultisignedResponse>
360
- public request(r: SubscribeRequest): Promise<SubscribeResponse>
361
- public request(r: UnsubscribeRequest): Promise<UnsubscribeResponse>
362
- public async request(
363
- r: TransactionEntryRequest,
364
- ): Promise<TransactionEntryResponse>
365
- public async request(r: TxRequest): Promise<TxResponse>
366
- public async request<R extends BaseRequest, T extends BaseResponse>(
367
- r: R,
368
- ): Promise<T>
369
289
  /**
370
290
  * Makes a request to the client with the given command and
371
291
  * additional request body parameters.
372
292
  *
293
+ * @category Network
294
+ *
373
295
  * @param req - Request to send to the server.
374
296
  * @returns The response from the server.
375
- * @category Network
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * const response = await client.request({
301
+ * command: 'account_info',
302
+ * account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
303
+ * })
304
+ * console.log(response)
305
+ * ```
376
306
  */
377
- public async request<R extends Request, T extends Response>(
307
+ public async request<R extends Request, T = RequestResponseMap<R>>(
378
308
  req: R,
379
309
  ): Promise<T> {
380
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Necessary for overloading
381
- const response = (await this.connection.request({
310
+ const response = await this.connection.request<R, T>({
382
311
  ...req,
383
312
  account: req.account
384
313
  ? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Must be string
385
314
  ensureClassicAddress(req.account as string)
386
315
  : undefined,
387
- })) as T
316
+ })
388
317
 
389
318
  // mutates `response` to add warnings
390
319
  handlePartialPayment(req.command, response)
@@ -392,44 +321,34 @@ class Client extends EventEmitter {
392
321
  return response
393
322
  }
394
323
 
395
- /**
396
- * @category Network
397
- */
398
- public async requestNextPage(
399
- req: AccountChannelsRequest,
400
- resp: AccountChannelsResponse,
401
- ): Promise<AccountChannelsResponse>
402
- public async requestNextPage(
403
- req: AccountLinesRequest,
404
- resp: AccountLinesResponse,
405
- ): Promise<AccountLinesResponse>
406
- public async requestNextPage(
407
- req: AccountObjectsRequest,
408
- resp: AccountObjectsResponse,
409
- ): Promise<AccountObjectsResponse>
410
- public async requestNextPage(
411
- req: AccountOffersRequest,
412
- resp: AccountOffersResponse,
413
- ): Promise<AccountOffersResponse>
414
- public async requestNextPage(
415
- req: AccountTxRequest,
416
- resp: AccountTxResponse,
417
- ): Promise<AccountTxResponse>
418
- public async requestNextPage(
419
- req: LedgerDataRequest,
420
- resp: LedgerDataResponse,
421
- ): Promise<LedgerDataResponse>
422
324
  /**
423
325
  * Requests the next page of data.
424
326
  *
327
+ * @category Network
328
+ *
425
329
  * @param req - Request to send.
426
330
  * @param resp - Response with the marker to use in the request.
427
331
  * @returns The response with the next page of data.
332
+ *
333
+ * @example
334
+ * ```ts
335
+ * const response = await client.request({
336
+ * command: 'account_tx',
337
+ * account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
338
+ * })
339
+ * console.log(response)
340
+ * const nextResponse = await client.requestNextPage({
341
+ * command: 'account_tx',
342
+ * account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
343
+ * },
344
+ * response)
345
+ * console.log(nextResponse)
346
+ * ```
428
347
  */
429
348
  public async requestNextPage<
430
- T extends MarkerRequest,
431
- U extends MarkerResponse,
432
- >(req: T, resp: U): Promise<U> {
349
+ T extends RequestNextPageType,
350
+ U extends RequestNextPageReturnMap<T>,
351
+ >(req: T, resp: U): Promise<RequestNextPageReturnMap<T>> {
433
352
  if (!resp.result.marker) {
434
353
  return Promise.reject(
435
354
  new NotFoundError('response does not have a next page'),
@@ -443,7 +362,13 @@ class Client extends EventEmitter {
443
362
  /**
444
363
  * Event handler for subscription streams.
445
364
  *
446
- * @example
365
+ * @category Network
366
+ *
367
+ * @param eventName - Name of the event. Only forwards streams.
368
+ * @param listener - Function to run on event.
369
+ * @returns This, because it inherits from EventEmitter.
370
+ *
371
+ * * @example
447
372
  * ```ts
448
373
  * const api = new Client('wss://s.altnet.rippletest.net:51233')
449
374
  *
@@ -458,68 +383,15 @@ class Client extends EventEmitter {
458
383
  * streams: ['transactions_proposed']
459
384
  * })
460
385
  * ```
461
- *
462
- * @category Network
463
- */
464
- public on(event: 'connected', listener: () => void): this
465
- public on(event: 'disconnected', listener: (code: number) => void): this
466
- public on(
467
- event: 'ledgerClosed',
468
- listener: (ledger: LedgerStream) => void,
469
- ): this
470
- public on(
471
- event: 'validationReceived',
472
- listener: (validation: ValidationStream) => void,
473
- ): this
474
- public on(
475
- event: 'transaction',
476
- listener: (tx: TransactionStream) => void,
477
- ): this
478
- public on(
479
- event: 'peerStatusChange',
480
- listener: (status: PeerStatusStream) => void,
481
- ): this
482
- public on(
483
- event: 'consensusPhase',
484
- listener: (phase: ConsensusStream) => void,
485
- ): this
486
- public on(
487
- event: 'manifestReceived',
488
- listener: (manifest: ManifestResponse) => void,
489
- ): this
490
- public on(event: 'path_find', listener: (path: PathFindStream) => void): this
491
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- needs to be any for overload
492
- public on(event: 'error', listener: (...err: any[]) => void): this
493
- /**
494
- * Event handler for subscription streams.
495
- *
496
- * @param eventName - Name of the event. Only forwards streams.
497
- * @param listener - Function to run on event.
498
- * @returns This, because it inherits from EventEmitter.
499
386
  */
500
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- needs to be any for overload
501
- public on(eventName: string, listener: (...args: any[]) => void): this {
387
+ public on<
388
+ T extends EventTypes,
389
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- needs to be any for overload
390
+ U extends (...args: any[]) => void = OnEventToListenerMap<T>,
391
+ >(eventName: T, listener: U): this {
502
392
  return super.on(eventName, listener)
503
393
  }
504
394
 
505
- /**
506
- * @category Network
507
- */
508
- public async requestAll(
509
- req: AccountChannelsRequest,
510
- ): Promise<AccountChannelsResponse[]>
511
- public async requestAll(
512
- req: AccountLinesRequest,
513
- ): Promise<AccountLinesResponse[]>
514
- public async requestAll(
515
- req: AccountObjectsRequest,
516
- ): Promise<AccountObjectsResponse[]>
517
- public async requestAll(
518
- req: AccountOffersRequest,
519
- ): Promise<AccountOffersResponse[]>
520
- public async requestAll(req: AccountTxRequest): Promise<AccountTxResponse[]>
521
- public async requestAll(req: BookOffersRequest): Promise<BookOffersResponse[]>
522
- public async requestAll(req: LedgerDataRequest): Promise<LedgerDataResponse[]>
523
395
  /**
524
396
  * Makes multiple paged requests to the client to return a given number of
525
397
  * resources. Multiple paged requests will be made until the `limit`
@@ -533,15 +405,27 @@ class Client extends EventEmitter {
533
405
  * general use. Instead, use rippled's built-in pagination and make multiple
534
406
  * requests as needed.
535
407
  *
408
+ * @category Network
409
+ *
536
410
  * @param request - The initial request to send to the server.
537
411
  * @param collect - (Optional) the param to use to collect the array of resources (only needed if command is unknown).
538
412
  * @returns The array of all responses.
539
413
  * @throws ValidationError if there is no collection key (either from a known command or for the unknown command).
414
+ *
415
+ * @example
416
+ * // Request all ledger data pages
417
+ * const allResponses = await client.requestAll({ command: 'ledger_data' });
418
+ * console.log(allResponses);
419
+ *
420
+ * @example
421
+ * // Request all transaction data pages
422
+ * const allResponses = await client.requestAll({ command: 'transaction_data' });
423
+ * console.log(allResponses);
540
424
  */
541
- public async requestAll<T extends MarkerRequest, U extends MarkerResponse>(
542
- request: T,
543
- collect?: string,
544
- ): Promise<U[]> {
425
+ public async requestAll<
426
+ T extends MarkerRequest,
427
+ U = RequestAllResponseMap<T>,
428
+ >(request: T, collect?: string): Promise<U[]> {
545
429
  /*
546
430
  * The data under collection is keyed based on the command. Fail if command
547
431
  * not recognized and collection key not provided.
@@ -569,7 +453,7 @@ class Client extends EventEmitter {
569
453
  // eslint-disable-next-line no-await-in-loop -- Necessary for this, it really has to wait
570
454
  const singleResponse = await this.connection.request(repeatProps)
571
455
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Should be true
572
- const singleResult = (singleResponse as U).result
456
+ const singleResult = (singleResponse as MarkerResponse).result
573
457
  if (!(collectKey in singleResult)) {
574
458
  throw new XrplError(`${collectKey} not in result`)
575
459
  }
@@ -591,6 +475,16 @@ class Client extends EventEmitter {
591
475
 
592
476
  /**
593
477
  * Get networkID and buildVersion from server_info
478
+ *
479
+ * @returns void
480
+ * @example
481
+ * ```ts
482
+ * const { Client } = require('xrpl')
483
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
484
+ * await client.getServerInfo()
485
+ * console.log(client.networkID)
486
+ * console.log(client.buildVersion)
487
+ * ```
594
488
  */
595
489
  public async getServerInfo(): Promise<void> {
596
490
  try {
@@ -623,6 +517,15 @@ class Client extends EventEmitter {
623
517
  * before exiting your application.
624
518
  * @returns A promise that resolves with a void value when a connection is established.
625
519
  * @category Network
520
+ *
521
+ * @example
522
+ * ```ts
523
+ * const { Client } = require('xrpl')
524
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
525
+ * await client.connect()
526
+ * // do something with the client
527
+ * await client.disconnect()
528
+ * ```
626
529
  */
627
530
  public async connect(): Promise<void> {
628
531
  return this.connection.connect().then(async () => {
@@ -664,54 +567,583 @@ class Client extends EventEmitter {
664
567
  *
665
568
  * @returns Whether the client instance is connected.
666
569
  * @category Network
570
+ * @example
571
+ * ```ts
572
+ * const { Client } = require('xrpl')
573
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
574
+ * await client.connect()
575
+ * console.log(client.isConnected())
576
+ * // true
577
+ * await client.disconnect()
578
+ * console.log(client.isConnected())
579
+ * // false
580
+ * ```
667
581
  */
668
582
  public isConnected(): boolean {
669
583
  return this.connection.isConnected()
670
584
  }
671
585
 
672
586
  /**
587
+ * Autofills fields in a transaction. This will set `Sequence`, `Fee`,
588
+ * `lastLedgerSequence` according to the current state of the server this Client
589
+ * is connected to. It also converts all X-Addresses to classic addresses and
590
+ * flags interfaces into numbers.
591
+ *
673
592
  * @category Core
593
+ *
594
+ * @example
595
+ *
596
+ * ```ts
597
+ * const { Client } = require('xrpl')
598
+ *
599
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
600
+ *
601
+ * async function createAndAutofillTransaction() {
602
+ * const transaction = {
603
+ * TransactionType: 'Payment',
604
+ * Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
605
+ * Destination: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
606
+ * Amount: '10000000' // 10 XRP in drops (1/1,000,000th of an XRP)
607
+ * }
608
+ *
609
+ * try {
610
+ * const autofilledTransaction = await client.autofill(transaction)
611
+ * console.log(autofilledTransaction)
612
+ * } catch (error) {
613
+ * console.error(`Failed to autofill transaction: ${error}`)
614
+ * }
615
+ * }
616
+ *
617
+ * createAndAutofillTransaction()
618
+ * ```
619
+ *
620
+ * Autofill helps fill in fields which should be included in a transaction, but can be determined automatically
621
+ * such as `LastLedgerSequence` and `Fee`. If you override one of the fields `autofill` changes, your explicit
622
+ * values will be used instead. By default, this is done as part of `submit` and `submitAndWait` when you pass
623
+ * in an unsigned transaction along with your wallet to be submitted.
624
+ *
625
+ * @template T
626
+ * @param transaction - A {@link SubmittableTransaction} in JSON format
627
+ * @param signersCount - The expected number of signers for this transaction.
628
+ * Only used for multisigned transactions.
629
+ * @returns The autofilled transaction.
674
630
  */
675
- public autofill = autofill
631
+ public async autofill<T extends SubmittableTransaction>(
632
+ transaction: T,
633
+ signersCount?: number,
634
+ ): Promise<T> {
635
+ const tx = { ...transaction }
636
+
637
+ setValidAddresses(tx)
638
+
639
+ setTransactionFlagsToNumber(tx)
640
+
641
+ const promises: Array<Promise<void>> = []
642
+ if (tx.NetworkID == null) {
643
+ tx.NetworkID = txNeedsNetworkID(this) ? this.networkID : undefined
644
+ }
645
+ if (tx.Sequence == null) {
646
+ promises.push(setNextValidSequenceNumber(this, tx))
647
+ }
648
+ if (tx.Fee == null) {
649
+ promises.push(calculateFeePerTransactionType(this, tx, signersCount))
650
+ }
651
+ if (tx.LastLedgerSequence == null) {
652
+ promises.push(setLatestValidatedLedgerSequence(this, tx))
653
+ }
654
+ if (tx.TransactionType === 'AccountDelete') {
655
+ promises.push(checkAccountDeleteBlockers(this, tx))
656
+ }
657
+
658
+ return Promise.all(promises).then(() => tx)
659
+ }
676
660
 
677
661
  /**
662
+ * Submits a signed/unsigned transaction.
663
+ * Steps performed on a transaction:
664
+ * 1. Autofill.
665
+ * 2. Sign & Encode.
666
+ * 3. Submit.
667
+ *
678
668
  * @category Core
669
+ *
670
+ * @param transaction - A transaction to autofill, sign & encode, and submit.
671
+ * @param opts - (Optional) Options used to sign and submit a transaction.
672
+ * @param opts.autofill - If true, autofill a transaction.
673
+ * @param opts.failHard - If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
674
+ * @param opts.wallet - A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
675
+ *
676
+ * @returns A promise that contains SubmitResponse.
677
+ * @throws RippledError if submit request fails.
678
+ *
679
+ * @example
680
+ * ```ts
681
+ * const { Client, Wallet } = require('xrpl')
682
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
683
+ * await client.connect()
684
+ * const wallet = Wallet.generate()
685
+ * const transaction = {
686
+ * TransactionType: 'Payment',
687
+ * Account: wallet.classicAddress,
688
+ * Destination: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
689
+ * Amount: '10000000' // 10 XRP in drops (1/1,000,000th of an XRP)
690
+ * }
691
+ * const submitResponse = await client.submit(transaction, { wallet })
692
+ * console.log(submitResponse)
693
+ * ```
679
694
  */
680
- public submit = submit
695
+ public async submit(
696
+ transaction: SubmittableTransaction | string,
697
+ opts?: {
698
+ // If true, autofill a transaction.
699
+ autofill?: boolean
700
+ // If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
701
+ failHard?: boolean
702
+ // A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
703
+ wallet?: Wallet
704
+ },
705
+ ): Promise<SubmitResponse> {
706
+ const signedTx = await getSignedTx(this, transaction, opts)
707
+ return submitRequest(this, signedTx, opts?.failHard)
708
+ }
709
+
681
710
  /**
711
+ * Asynchronously submits a transaction and verifies that it has been included in a
712
+ * validated ledger (or has errored/will not be included for some reason).
713
+ * See [Reliable Transaction Submission](https://xrpl.org/reliable-transaction-submission.html).
714
+ *
682
715
  * @category Core
716
+ *
717
+ * @example
718
+ *
719
+ * ```ts
720
+ * const { Client, Wallet } = require('xrpl')
721
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
722
+ *
723
+ * async function submitTransaction() {
724
+ * const senderWallet = client.fundWallet()
725
+ * const recipientWallet = client.fundWallet()
726
+ *
727
+ * const transaction = {
728
+ * TransactionType: 'Payment',
729
+ * Account: senderWallet.address,
730
+ * Destination: recipientWallet.address,
731
+ * Amount: '10'
732
+ * }
733
+ *
734
+ * try {
735
+ * await client.submit(signedTransaction, { wallet: senderWallet })
736
+ * console.log(result)
737
+ * } catch (error) {
738
+ * console.error(`Failed to submit transaction: ${error}`)
739
+ * }
740
+ * }
741
+ *
742
+ * submitTransaction()
743
+ * ```
744
+ *
745
+ * In this example we submit a payment transaction between two newly created testnet accounts.
746
+ *
747
+ * Under the hood, `submit` will call `client.autofill` by default, and because we've passed in a `Wallet` it
748
+ * Will also sign the transaction for us before submitting the signed transaction binary blob to the ledger.
749
+ *
750
+ * This is similar to `submitAndWait` which does all of the above, but also waits to see if the transaction has been validated.
751
+ * @param transaction - A transaction to autofill, sign & encode, and submit.
752
+ * @param opts - (Optional) Options used to sign and submit a transaction.
753
+ * @param opts.autofill - If true, autofill a transaction.
754
+ * @param opts.failHard - If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
755
+ * @param opts.wallet - A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
756
+ * @throws Connection errors: If the `Client` object is unable to establish a connection to the specified WebSocket endpoint,
757
+ * an error will be thrown.
758
+ * @throws Transaction errors: If the submitted transaction is invalid or cannot be included in a validated ledger for any
759
+ * reason, the promise returned by `submitAndWait()` will be rejected with an error. This could include issues with insufficient
760
+ * balance, invalid transaction fields, or other issues specific to the transaction being submitted.
761
+ * @throws Ledger errors: If the ledger being used to submit the transaction is undergoing maintenance or otherwise unavailable,
762
+ * an error will be thrown.
763
+ * @throws Timeout errors: If the transaction takes longer than the specified timeout period to be included in a validated
764
+ * ledger, the promise returned by `submitAndWait()` will be rejected with an error.
765
+ * @returns A promise that contains TxResponse, that will return when the transaction has been validated.
683
766
  */
684
- public submitAndWait = submitAndWait
767
+ public async submitAndWait<
768
+ T extends SubmittableTransaction = SubmittableTransaction,
769
+ >(
770
+ transaction: T | string,
771
+ opts?: {
772
+ // If true, autofill a transaction.
773
+ autofill?: boolean
774
+ // If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
775
+ failHard?: boolean
776
+ // A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
777
+ wallet?: Wallet
778
+ },
779
+ ): Promise<TxResponse<T>> {
780
+ const signedTx = await getSignedTx(this, transaction, opts)
781
+
782
+ const lastLedger = getLastLedgerSequence(signedTx)
783
+ if (lastLedger == null) {
784
+ throw new ValidationError(
785
+ 'Transaction must contain a LastLedgerSequence value for reliable submission.',
786
+ )
787
+ }
788
+
789
+ const response = await submitRequest(this, signedTx, opts?.failHard)
790
+
791
+ const txHash = hashes.hashSignedTx(signedTx)
792
+ return waitForFinalTransactionOutcome(
793
+ this,
794
+ txHash,
795
+ lastLedger,
796
+ response.result.engine_result,
797
+ )
798
+ }
685
799
 
686
800
  /**
801
+ * Deprecated: Use autofill instead, provided for users familiar with v1
802
+ *
803
+ * @param transaction - A {@link Transaction} in JSON format
804
+ * @param signersCount - The expected number of signers for this transaction.
805
+ * Only used for multisigned transactions.
687
806
  * @deprecated Use autofill instead, provided for users familiar with v1
688
807
  */
689
- public prepareTransaction = autofill
808
+ public async prepareTransaction(
809
+ transaction: SubmittableTransaction,
810
+ signersCount?: number,
811
+ ): ReturnType<Client['autofill']> {
812
+ return this.autofill(transaction, signersCount)
813
+ }
690
814
 
691
815
  /**
816
+ * Retrieves the XRP balance of a given account address.
817
+ *
692
818
  * @category Abstraction
819
+ *
820
+ * @example
821
+ * ```ts
822
+ * const client = new Client(wss://s.altnet.rippletest.net:51233)
823
+ * await client.connect()
824
+ * const balance = await client.getXrpBalance('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn')
825
+ * console.log(balance)
826
+ * await client.disconnect()
827
+ * /// '200'
828
+ * ```
829
+ *
830
+ * @param address - The XRP address to retrieve the balance for.
831
+ * @param [options] - Additional options for fetching the balance (optional).
832
+ * @param [options.ledger_hash] - The hash of the ledger to retrieve the balance from (optional).
833
+ * @param [options.ledger_index] - The index of the ledger to retrieve the balance from (optional).
834
+ * @returns A promise that resolves with the XRP balance as a number.
693
835
  */
694
- public getXrpBalance = getXrpBalance
836
+ public async getXrpBalance(
837
+ address: string,
838
+ options: {
839
+ ledger_hash?: string
840
+ ledger_index?: LedgerIndex
841
+ } = {},
842
+ ): Promise<number> {
843
+ const xrpRequest: AccountInfoRequest = {
844
+ command: 'account_info',
845
+ account: address,
846
+ ledger_index: options.ledger_index ?? 'validated',
847
+ ledger_hash: options.ledger_hash,
848
+ }
849
+ const response = await this.request(xrpRequest)
850
+ return dropsToXrp(response.result.account_data.Balance)
851
+ }
695
852
 
696
853
  /**
854
+ * Get XRP/non-XRP balances for an account.
855
+ *
697
856
  * @category Abstraction
857
+ *
858
+ * @example
859
+ * ```ts
860
+ * const { Client } = require('xrpl')
861
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
862
+ * await client.connect()
863
+ *
864
+ * async function getAccountBalances(address) {
865
+ * try {
866
+ * const options = {
867
+ * ledger_index: 'validated',
868
+ * limit: 10
869
+ * };
870
+ *
871
+ * const balances = await xrplClient.getBalances(address, options);
872
+ *
873
+ * console.log('Account Balances:');
874
+ * balances.forEach((balance) => {
875
+ * console.log(`Currency: ${balance.currency}`);
876
+ * console.log(`Value: ${balance.value}`);
877
+ * console.log(`Issuer: ${balance.issuer}`);
878
+ * console.log('---');
879
+ * });
880
+ * } catch (error) {
881
+ * console.error('Error retrieving account balances:', error);
882
+ * }
883
+ * }
884
+ *
885
+ * const address = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
886
+ * await getAccountBalances(address);
887
+ * await client.disconnect();
888
+ * ```
889
+ *
890
+ * @param address - Address of the account to retrieve balances for.
891
+ * @param options - Allows the client to specify a ledger_hash, ledger_index,
892
+ * filter by peer, and/or limit number of balances.
893
+ * @param options.ledger_index - Retrieve the account balances at a given
894
+ * ledger_index.
895
+ * @param options.ledger_hash - Retrieve the account balances at the ledger with
896
+ * a given ledger_hash.
897
+ * @param options.peer - Filter balances by peer.
898
+ * @param options.limit - Limit number of balances to return.
899
+ * @returns An array of XRP/non-XRP balances for the given account.
698
900
  */
699
- public getBalances = getBalances
901
+ // eslint-disable-next-line max-lines-per-function -- Longer definition is required for end users to see the definition.
902
+ public async getBalances(
903
+ address: string,
904
+ options: {
905
+ ledger_hash?: string
906
+ ledger_index?: LedgerIndex
907
+ peer?: string
908
+ limit?: number
909
+ } = {},
910
+ ): Promise<
911
+ Array<{ value: string; currency: string; issuer?: string | undefined }>
912
+ > {
913
+ const balances: Balance[] = []
914
+
915
+ // get XRP balance
916
+ let xrpPromise: Promise<number> = Promise.resolve(0)
917
+ if (!options.peer) {
918
+ xrpPromise = this.getXrpBalance(address, {
919
+ ledger_hash: options.ledger_hash,
920
+ ledger_index: options.ledger_index,
921
+ })
922
+ }
923
+
924
+ // get non-XRP balances
925
+ const linesRequest: AccountLinesRequest = {
926
+ command: 'account_lines',
927
+ account: address,
928
+ ledger_index: options.ledger_index ?? 'validated',
929
+ ledger_hash: options.ledger_hash,
930
+ peer: options.peer,
931
+ limit: options.limit,
932
+ }
933
+ const linesPromise = this.requestAll(linesRequest)
934
+
935
+ // combine results
936
+ await Promise.all([xrpPromise, linesPromise]).then(
937
+ ([xrpBalance, linesResponses]) => {
938
+ const accountLinesBalance = linesResponses.flatMap((response) =>
939
+ formatBalances(response.result.lines),
940
+ )
941
+ if (xrpBalance !== 0) {
942
+ balances.push({ currency: 'XRP', value: xrpBalance.toString() })
943
+ }
944
+ balances.push(...accountLinesBalance)
945
+ },
946
+ )
947
+ return balances.slice(0, options.limit)
948
+ }
700
949
 
701
950
  /**
951
+ * Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook
952
+ * by making two `order_book` requests (with the second reversing takerPays and takerGets). Returned offers are
953
+ * not normalized in this function, so either currency could be takerGets or takerPays.
954
+ *
702
955
  * @category Abstraction
956
+ *
957
+ * @param currency1 - Specification of one currency involved. (With a currency code and optionally an issuer)
958
+ * @param currency2 - Specification of a second currency involved. (With a currency code and optionally an issuer)
959
+ * @param options - Options allowing the client to specify ledger_index,
960
+ * ledger_hash, filter by taker, and/or limit number of orders.
961
+ * @param options.ledger_index - Retrieve the orderbook at a given ledger_index.
962
+ * @param options.ledger_hash - Retrieve the orderbook at the ledger with a
963
+ * given ledger_hash.
964
+ * @param options.taker - Filter orders by taker.
965
+ * @param options.limit - The limit passed into each book_offers request.
966
+ * Can return more than this due to two calls being made. Defaults to 20.
967
+ * @returns An object containing buy and sell objects.
703
968
  */
704
- public getOrderbook = getOrderbook
969
+
970
+ public async getOrderbook(
971
+ currency1: BookOfferCurrency,
972
+ currency2: BookOfferCurrency,
973
+ options: {
974
+ limit?: number
975
+ ledger_index?: LedgerIndex
976
+ ledger_hash?: string | null
977
+ taker?: string | null
978
+ } = {},
979
+ ): Promise<{
980
+ buy: BookOffer[]
981
+ sell: BookOffer[]
982
+ }> {
983
+ validateOrderbookOptions(options)
984
+
985
+ const request = createBookOffersRequest(currency1, currency2, options)
986
+
987
+ const directOfferResults = await requestAllOffers(this, request)
988
+ const reverseOfferResults = await requestAllOffers(
989
+ this,
990
+ reverseRequest(request),
991
+ )
992
+
993
+ const directOffers = extractOffers(directOfferResults)
994
+ const reverseOffers = extractOffers(reverseOfferResults)
995
+
996
+ const orders = combineOrders(directOffers, reverseOffers)
997
+
998
+ const { buy, sell } = separateBuySellOrders(orders)
999
+
1000
+ /*
1001
+ * Sort the orders
1002
+ * for both buys and sells, lowest quality is closest to mid-market
1003
+ * we sort the orders so that earlier orders are closer to mid-market
1004
+ */
1005
+ return {
1006
+ buy: sortAndLimitOffers(buy, options.limit),
1007
+ sell: sortAndLimitOffers(sell, options.limit),
1008
+ }
1009
+ }
705
1010
 
706
1011
  /**
1012
+ * Returns the index of the most recently validated ledger.
1013
+ *
707
1014
  * @category Abstraction
1015
+ *
1016
+ * @returns The most recently validated ledger index.
1017
+ *
1018
+ * @example
1019
+ * ```ts
1020
+ * const { Client } = require('xrpl')
1021
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
1022
+ * await client.connect()
1023
+ * const ledgerIndex = await client.getLedgerIndex()
1024
+ * console.log(ledgerIndex)
1025
+ * // 884039
1026
+ * ```
708
1027
  */
709
- public getLedgerIndex = getLedgerIndex
1028
+ public async getLedgerIndex(): Promise<number> {
1029
+ const ledgerResponse = await this.request({
1030
+ command: 'ledger',
1031
+ ledger_index: 'validated',
1032
+ })
1033
+ return ledgerResponse.result.ledger_index
1034
+ }
710
1035
 
711
1036
  /**
1037
+ * The fundWallet() method is used to send an amount of XRP (usually 1000) to a new (randomly generated)
1038
+ * or existing XRP Ledger wallet.
1039
+ *
712
1040
  * @category Faucet
1041
+ *
1042
+ * @example
1043
+ *
1044
+ * Example 1: Fund a randomly generated wallet
1045
+ * const { Client, Wallet } = require('xrpl')
1046
+ *
1047
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
1048
+ * await client.connect()
1049
+ * const { balance, wallet } = await client.fundWallet()
1050
+ *
1051
+ * Under the hood, this will use `Wallet.generate()` to create a new random wallet, then ask a testnet faucet
1052
+ * To send it XRP on ledger to make it a real account. If successful, this will return the new account balance in XRP
1053
+ * Along with the Wallet object to track the keys for that account. If you'd like, you can also re-fill an existing
1054
+ * Account by passing in a Wallet you already have.
1055
+ * ```ts
1056
+ * const api = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
1057
+ * await api.connect()
1058
+ * const { wallet, balance } = await api.fundWallet()
1059
+ * ```
1060
+ *
1061
+ * Example 2: Fund wallet using a custom faucet host and known wallet address
1062
+ *
1063
+ * `fundWallet` will try to infer the url of a faucet API from the network your client is connected to.
1064
+ * There are hardcoded default faucets for popular test networks like testnet and devnet.
1065
+ * However, if you're working with a newer or more obscure network, you may have to specify the faucetHost
1066
+ * And faucetPath so `fundWallet` can ask that faucet to fund your wallet.
1067
+ *
1068
+ * ```ts
1069
+ * const newWallet = Wallet.generate()
1070
+ * const { balance, wallet } = await client.fundWallet(newWallet, {
1071
+ * amount: '10',
1072
+ * faucetHost: 'https://custom-faucet.example.com',
1073
+ * faucetPath: '/accounts'
1074
+ * })
1075
+ * console.log(`Sent 10 XRP to wallet: ${address} from the given faucet. Resulting balance: ${balance} XRP`)
1076
+ * } catch (error) {
1077
+ * console.error(`Failed to fund wallet: ${error}`)
1078
+ * }
1079
+ * }
1080
+ * ```
1081
+ *
1082
+ * @param wallet - An existing XRPL Wallet to fund. If undefined or null, a new Wallet will be created.
1083
+ * @param options - See below.
1084
+ * @param options.faucetHost - A custom host for a faucet server. On devnet,
1085
+ * testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
1086
+ * attempt to determine the correct server automatically. In other environments,
1087
+ * or if you would like to customize the faucet host in devnet or testnet,
1088
+ * you should provide the host using this option.
1089
+ * @param options.faucetPath - A custom path for a faucet server. On devnet,
1090
+ * testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
1091
+ * attempt to determine the correct path automatically. In other environments,
1092
+ * or if you would like to customize the faucet path in devnet or testnet,
1093
+ * you should provide the path using this option.
1094
+ * Ex: client.fundWallet(null,{'faucet.altnet.rippletest.net', '/accounts'})
1095
+ * specifies a request to 'faucet.altnet.rippletest.net/accounts' to fund a new wallet.
1096
+ * @param options.amount - A custom amount to fund, if undefined or null, the default amount will be 1000.
1097
+ * @returns A Wallet on the Testnet or Devnet that contains some amount of XRP,
1098
+ * and that wallet's balance in XRP.
1099
+ * @throws When either Client isn't connected or unable to fund wallet address.
713
1100
  */
714
- public fundWallet = fundWallet
1101
+ public async fundWallet(
1102
+ this: Client,
1103
+ wallet?: Wallet | null,
1104
+ options: FundingOptions = {},
1105
+ ): Promise<{
1106
+ wallet: Wallet
1107
+ balance: number
1108
+ }> {
1109
+ if (!this.isConnected()) {
1110
+ throw new RippledError('Client not connected, cannot call faucet')
1111
+ }
1112
+ const existingWallet = Boolean(wallet)
1113
+
1114
+ // Generate a new Wallet if no existing Wallet is provided or its address is invalid to fund
1115
+ const walletToFund =
1116
+ wallet && isValidClassicAddress(wallet.classicAddress)
1117
+ ? wallet
1118
+ : Wallet.generate()
1119
+
1120
+ // Create the POST request body
1121
+ const postBody: FaucetRequestBody = {
1122
+ destination: walletToFund.classicAddress,
1123
+ xrpAmount: options.amount,
1124
+ usageContext: options.usageContext,
1125
+ userAgent: 'xrpl.js',
1126
+ }
1127
+
1128
+ let startingBalance = 0
1129
+ if (existingWallet) {
1130
+ try {
1131
+ startingBalance = Number(
1132
+ await this.getXrpBalance(walletToFund.classicAddress),
1133
+ )
1134
+ } catch {
1135
+ /* startingBalance remains what it was previously */
1136
+ }
1137
+ }
1138
+
1139
+ return requestFunding(
1140
+ options,
1141
+ this,
1142
+ startingBalance,
1143
+ walletToFund,
1144
+ postBody,
1145
+ )
1146
+ }
715
1147
  }
716
1148
 
717
1149
  export { Client }