+
+
+
+
\ No newline at end of file
diff --git a/_code-samples/modular-tutorials/send-mpt.js b/_code-samples/modular-tutorials/send-mpt.js
new file mode 100644
index 00000000000..c41c7d06965
--- /dev/null
+++ b/_code-samples/modular-tutorials/send-mpt.js
@@ -0,0 +1,113 @@
+// *******************************************************
+// ********************* Send MPT ************************
+// *******************************************************
+
+async function sendMPT() {
+ let net = getNet()
+ const client = new xrpl.Client(net)
+ await client.connect()
+ let results = `===Connected to ${net}. Sending MPT.===\n`
+ resultField.value = results
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const mpt_issuance_id = mptIdField.value
+ const mpt_quantity = amountField.value
+ const send_mpt_tx = {
+ "TransactionType": "Payment",
+ "Account": wallet.address,
+ "Amount": {
+ "mpt_issuance_id": mpt_issuance_id,
+ "value": mpt_quantity,
+ },
+ "Destination": destinationField.value,
+ }
+ const pay_prepared = await client.autofill(send_mpt_tx)
+ const pay_signed = wallet.sign(pay_prepared)
+ results = `\n===Sending ${mpt_quantity} ${mpt_issuance_id} to ${destinationField.value} ...`
+ resultField.value += results
+ const pay_result = await client.submitAndWait(pay_signed.tx_blob)
+ results = '\n\n===Transaction succeeded.\n'
+ results += JSON.stringify(pay_result.result, null, 2)
+ resultField.value += results
+ } catch (error) {
+ results = `Error sending MPT: ${error}`
+ resultField.value += results
+ }
+ finally {
+ client.disconnect()
+ }
+} // end of sendMPT()
+
+// *******************************************************
+// ******************** Get MPTs *************************
+// *******************************************************
+
+async function getMPTs() {
+ let net = getNet()
+ const client = new xrpl.Client(net)
+ await client.connect()
+ let results = ''
+ resultField.value = `===Connected to ${net}. Getting MPTs.===`
+
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const mpts = await client.request({
+ command: "account_objects",
+ account: wallet.address,
+ ledger_index: "validated",
+ type: "mptoken"
+ })
+ let JSONString = JSON.stringify(mpts.result, null, 2)
+ let JSONParse = JSON.parse(JSONString)
+ let numberOfMPTs = JSONParse.account_objects.length
+ let x = 0
+ while (x < numberOfMPTs){
+ results += "\n\n===MPT Issuance ID: " + JSONParse.account_objects[x].MPTokenIssuanceID
+ + "\n===MPT Amount: " + JSONParse.account_objects[x].MPTAmount
+ x++
+ }
+ results += "\n\n" + JSONString
+ resultField.value += results
+ } catch (error) {
+ results = `===Error getting MPTs: ${error}`
+ resultField.value += results
+ }
+ finally {
+ client.disconnect()
+ }
+} // End of getMPTs()
+
+// **********************************************************************
+// ****** MPTAuthorize Transaction ***************************************
+// **********************************************************************
+
+async function authorizeMPT() {
+ let net = getNet()
+ const client = new xrpl.Client(net)
+ await client.connect()
+ let results = `===Connected to ${net}. Authorizing MPT.===\n`
+ resultField.value = results
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const mpt_issuance_id = mptIdField.value
+ const auth_mpt_tx = {
+ "TransactionType": "MPTokenAuthorize",
+ "Account": wallet.address,
+ "MPTokenIssuanceID": mpt_issuance_id,
+ }
+ const auth_prepared = await client.autofill(auth_mpt_tx)
+ const auth_signed = wallet.sign(auth_prepared)
+ results += `\n\n===Sending authorization.===\n`
+ resultField.value = results
+ const auth_result = await client.submitAndWait(auth_signed.tx_blob)
+ results = '\n===Transaction succeeded===\n\n'
+ resultField.value += results
+ results += `\n\n` + JSON.stringify(auth_result.result, null, 2)
+ } catch (error) {
+ results = `===Error authorizing MPT: ${error}`
+ resultField.value = results
+ } finally {
+ resultField.value = results
+ }
+ client.disconnect()
+} // end of MPTAuthorize()
\ No newline at end of file
diff --git a/_code-samples/modular-tutorials/send-xrp.js b/_code-samples/modular-tutorials/send-xrp.js
new file mode 100644
index 00000000000..b5f054394e0
--- /dev/null
+++ b/_code-samples/modular-tutorials/send-xrp.js
@@ -0,0 +1,37 @@
+// *******************************************************
+// ******************** Send XRP *************************
+// *******************************************************
+async function sendXRP() {
+ const net = getNet()
+ const client = new xrpl.Client(net)
+ await client.connect()
+ let results = `===Connected to ${net}.===\n\nSending XRP.\n`
+ resultField.value = results
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const sendAmount = amountField.value
+ // -------------------------------------------------------- Prepare transaction
+ const prepared_tx = await client.autofill({
+ "TransactionType": "Payment",
+ "Account": wallet.address,
+ "Amount": xrpl.xrpToDrops(sendAmount),
+ "Destination": destinationField.value
+ })
+ // ------------------------------------------------- Sign prepared instructions
+ const signed = wallet.sign(prepared_tx)
+ // -------------------------------------------------------- Submit signed blob
+ const tx = await client.submitAndWait(signed.tx_blob)
+ results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
+ resultField.value = results
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
+ } catch (error) {
+ console.error('Error sending transaction:', error);
+ results += `\nError: ${error.message}\n`
+ resultField.value = results
+ throw error; // Re-throw the error to be handled by the caller
+ }
+ finally {
+ // Disconnect from the client
+ await xrplClient.disconnect();
+ }
+} // End of sendXRP()
\ No newline at end of file
diff --git a/_code-samples/quickstart/js/ripplex3-mint-nfts.js b/_code-samples/quickstart/js/ripplex3-mint-nfts.js
index 14ec69e35c8..0d5ae107c8d 100644
--- a/_code-samples/quickstart/js/ripplex3-mint-nfts.js
+++ b/_code-samples/quickstart/js/ripplex3-mint-nfts.js
@@ -27,8 +27,8 @@ async function mintToken() {
// ----------------------------------------------------- Submit signed blob
const tx = await client.submitAndWait(transactionJson, { wallet: standby_wallet} )
const nfts = await client.request({
- method: "account_nfts",
- account: standby_wallet.classicAddress
+ "method": "account_nfts",
+ "account": standby_wallet.classicAddress
})
// ------------------------------------------------------- Report results
diff --git a/docs/img/conditional-escrow1.png b/docs/img/conditional-escrow1.png
deleted file mode 100644
index 364ea085bf7..00000000000
Binary files a/docs/img/conditional-escrow1.png and /dev/null differ
diff --git a/docs/img/conditional-escrow3.png b/docs/img/conditional-escrow3.png
deleted file mode 100644
index 429d86f93ab..00000000000
Binary files a/docs/img/conditional-escrow3.png and /dev/null differ
diff --git a/docs/img/conditional-escrow4.png b/docs/img/conditional-escrow4.png
deleted file mode 100644
index 338a49cd9e8..00000000000
Binary files a/docs/img/conditional-escrow4.png and /dev/null differ
diff --git a/docs/img/conditional-escrow5.png b/docs/img/conditional-escrow5.png
deleted file mode 100644
index 6e268a79b44..00000000000
Binary files a/docs/img/conditional-escrow5.png and /dev/null differ
diff --git a/docs/img/module-create-offer-cancel-offer.png b/docs/img/module-create-offer-cancel-offer.png
deleted file mode 100644
index 8c6b77f95e2..00000000000
Binary files a/docs/img/module-create-offer-cancel-offer.png and /dev/null differ
diff --git a/docs/img/module-create-offer-cancelled-offer.png b/docs/img/module-create-offer-cancelled-offer.png
deleted file mode 100644
index 51cd9957b9d..00000000000
Binary files a/docs/img/module-create-offer-cancelled-offer.png and /dev/null differ
diff --git a/docs/img/module-create-offer-get-accounts.png b/docs/img/module-create-offer-get-accounts.png
deleted file mode 100644
index 5e354820acc..00000000000
Binary files a/docs/img/module-create-offer-get-accounts.png and /dev/null differ
diff --git a/docs/img/module-create-offer-get-balances.png b/docs/img/module-create-offer-get-balances.png
deleted file mode 100644
index 0799d105e56..00000000000
Binary files a/docs/img/module-create-offer-get-balances.png and /dev/null differ
diff --git a/docs/img/module-create-offer-get-offers.png b/docs/img/module-create-offer-get-offers.png
deleted file mode 100644
index 819fbf89ab9..00000000000
Binary files a/docs/img/module-create-offer-get-offers.png and /dev/null differ
diff --git a/docs/img/module-create-offer-xrp-for-usd.png b/docs/img/module-create-offer-xrp-for-usd.png
deleted file mode 100644
index bf21a14e1b3..00000000000
Binary files a/docs/img/module-create-offer-xrp-for-usd.png and /dev/null differ
diff --git a/docs/img/module-create-offer-xrp-for-usd2.png b/docs/img/module-create-offer-xrp-for-usd2.png
deleted file mode 100644
index 49af8663937..00000000000
Binary files a/docs/img/module-create-offer-xrp-for-usd2.png and /dev/null differ
diff --git a/docs/img/module-create-offer.png b/docs/img/module-create-offer.png
deleted file mode 100644
index 66ebbdf1eb6..00000000000
Binary files a/docs/img/module-create-offer.png and /dev/null differ
diff --git a/docs/img/mt-conditional-escrow-1-empty-form.png b/docs/img/mt-conditional-escrow-1-empty-form.png
new file mode 100644
index 00000000000..925d4294bb4
Binary files /dev/null and b/docs/img/mt-conditional-escrow-1-empty-form.png differ
diff --git a/docs/img/conditional-escrow2.png b/docs/img/mt-conditional-escrow-2-getConditionAndFulfillment.png
similarity index 100%
rename from docs/img/conditional-escrow2.png
rename to docs/img/mt-conditional-escrow-2-getConditionAndFulfillment.png
diff --git a/docs/img/mt-conditional-escrow-3-form-with-accounts.png b/docs/img/mt-conditional-escrow-3-form-with-accounts.png
new file mode 100644
index 00000000000..3eeb22595db
Binary files /dev/null and b/docs/img/mt-conditional-escrow-3-form-with-accounts.png differ
diff --git a/docs/img/mt-conditional-escrow-4-escrow-create.png b/docs/img/mt-conditional-escrow-4-escrow-create.png
new file mode 100644
index 00000000000..61317bb4631
Binary files /dev/null and b/docs/img/mt-conditional-escrow-4-escrow-create.png differ
diff --git a/docs/img/mt-conditional-escrow-5-escrow-fulfill.png b/docs/img/mt-conditional-escrow-5-escrow-fulfill.png
new file mode 100644
index 00000000000..fd518b9aed1
Binary files /dev/null and b/docs/img/mt-conditional-escrow-5-escrow-fulfill.png differ
diff --git a/docs/img/mt-conditional-escrow-6-get-escrows.png b/docs/img/mt-conditional-escrow-6-get-escrows.png
new file mode 100644
index 00000000000..e8f0d23e05d
Binary files /dev/null and b/docs/img/mt-conditional-escrow-6-get-escrows.png differ
diff --git a/docs/img/mt-conditional-escrow-7-sequence-value.png b/docs/img/mt-conditional-escrow-7-sequence-value.png
new file mode 100644
index 00000000000..3b95449b36e
Binary files /dev/null and b/docs/img/mt-conditional-escrow-7-sequence-value.png differ
diff --git a/docs/img/mt-create-offers-1-empty-form-info.png b/docs/img/mt-create-offers-1-empty-form-info.png
new file mode 100644
index 00000000000..b0aeab85e0e
Binary files /dev/null and b/docs/img/mt-create-offers-1-empty-form-info.png differ
diff --git a/docs/img/mt-create-offers-2-form-with-account-info.png b/docs/img/mt-create-offers-2-form-with-account-info.png
new file mode 100644
index 00000000000..48f66d50ce2
Binary files /dev/null and b/docs/img/mt-create-offers-2-form-with-account-info.png differ
diff --git a/docs/img/mt-create-offers-3-xrp-for-usd-offer.png b/docs/img/mt-create-offers-3-xrp-for-usd-offer.png
new file mode 100644
index 00000000000..8e6d8b6804c
Binary files /dev/null and b/docs/img/mt-create-offers-3-xrp-for-usd-offer.png differ
diff --git a/docs/img/mt-create-offers-4-matching-offer.png b/docs/img/mt-create-offers-4-matching-offer.png
new file mode 100644
index 00000000000..8a7785ae62c
Binary files /dev/null and b/docs/img/mt-create-offers-4-matching-offer.png differ
diff --git a/docs/img/mt-create-offers-5-sequence-number.png b/docs/img/mt-create-offers-5-sequence-number.png
new file mode 100644
index 00000000000..624bcdc4a15
Binary files /dev/null and b/docs/img/mt-create-offers-5-sequence-number.png differ
diff --git a/docs/img/mt-create-offers-6-no-offers.png b/docs/img/mt-create-offers-6-no-offers.png
new file mode 100644
index 00000000000..1235dfef557
Binary files /dev/null and b/docs/img/mt-create-offers-6-no-offers.png differ
diff --git a/docs/img/mt-send-checks-1-empty-form.png b/docs/img/mt-send-checks-1-empty-form.png
new file mode 100644
index 00000000000..9fb2043588c
Binary files /dev/null and b/docs/img/mt-send-checks-1-empty-form.png differ
diff --git a/docs/img/mt-send-checks-2-form-with-accounts.png b/docs/img/mt-send-checks-2-form-with-accounts.png
new file mode 100644
index 00000000000..81a708165c6
Binary files /dev/null and b/docs/img/mt-send-checks-2-form-with-accounts.png differ
diff --git a/docs/img/mt-send-checks-3-send-xrp.png b/docs/img/mt-send-checks-3-send-xrp.png
new file mode 100644
index 00000000000..14a1f7c2620
Binary files /dev/null and b/docs/img/mt-send-checks-3-send-xrp.png differ
diff --git a/docs/img/mt-send-checks-4-send-currency.png b/docs/img/mt-send-checks-4-send-currency.png
new file mode 100644
index 00000000000..c0c61914d58
Binary files /dev/null and b/docs/img/mt-send-checks-4-send-currency.png differ
diff --git a/docs/img/mt-send-checks-5-get-checks.png b/docs/img/mt-send-checks-5-get-checks.png
new file mode 100644
index 00000000000..a587cb5be66
Binary files /dev/null and b/docs/img/mt-send-checks-5-get-checks.png differ
diff --git a/docs/img/mt-send-checks-6-cash-check.png b/docs/img/mt-send-checks-6-cash-check.png
new file mode 100644
index 00000000000..ff5af4b4167
Binary files /dev/null and b/docs/img/mt-send-checks-6-cash-check.png differ
diff --git a/docs/img/mt-send-checks-7-get-balance.png b/docs/img/mt-send-checks-7-get-balance.png
new file mode 100644
index 00000000000..06541c9a3d3
Binary files /dev/null and b/docs/img/mt-send-checks-7-get-balance.png differ
diff --git a/docs/img/mt-send-checks-8-cancel-check.png b/docs/img/mt-send-checks-8-cancel-check.png
new file mode 100644
index 00000000000..40f73230d93
Binary files /dev/null and b/docs/img/mt-send-checks-8-cancel-check.png differ
diff --git a/docs/img/mt-send-currency-1-empty-form-info.png b/docs/img/mt-send-currency-1-empty-form-info.png
new file mode 100644
index 00000000000..745906dc34d
Binary files /dev/null and b/docs/img/mt-send-currency-1-empty-form-info.png differ
diff --git a/docs/img/mt-send-currency-2-distribute-accounts.png b/docs/img/mt-send-currency-2-distribute-accounts.png
new file mode 100644
index 00000000000..a5de8f3dd3c
Binary files /dev/null and b/docs/img/mt-send-currency-2-distribute-accounts.png differ
diff --git a/docs/img/mt-send-currency-3-create-trustline.png b/docs/img/mt-send-currency-3-create-trustline.png
new file mode 100644
index 00000000000..b82411ad3b9
Binary files /dev/null and b/docs/img/mt-send-currency-3-create-trustline.png differ
diff --git a/docs/img/mt-send-currency-4-send-currency.png b/docs/img/mt-send-currency-4-send-currency.png
new file mode 100644
index 00000000000..ff4190f9a53
Binary files /dev/null and b/docs/img/mt-send-currency-4-send-currency.png differ
diff --git a/docs/img/mt-send-currency-5-issuer-token-balance.png b/docs/img/mt-send-currency-5-issuer-token-balance.png
new file mode 100644
index 00000000000..efd31358d12
Binary files /dev/null and b/docs/img/mt-send-currency-5-issuer-token-balance.png differ
diff --git a/docs/img/mt-send-currency-6-holder-token-balance.png b/docs/img/mt-send-currency-6-holder-token-balance.png
new file mode 100644
index 00000000000..f7bca2cb91b
Binary files /dev/null and b/docs/img/mt-send-currency-6-holder-token-balance.png differ
diff --git a/docs/img/tut-send-mpt-0-empty-form.png b/docs/img/mt-send-mpt-0-empty-form.png
similarity index 100%
rename from docs/img/tut-send-mpt-0-empty-form.png
rename to docs/img/mt-send-mpt-0-empty-form.png
diff --git a/docs/img/tut-send-mpt-1-gathered-info.png b/docs/img/mt-send-mpt-1-gathered-info.png
similarity index 100%
rename from docs/img/tut-send-mpt-1-gathered-info.png
rename to docs/img/mt-send-mpt-1-gathered-info.png
diff --git a/docs/img/tut-send-mpt-2-account-2.png b/docs/img/mt-send-mpt-2-account-2.png
similarity index 100%
rename from docs/img/tut-send-mpt-2-account-2.png
rename to docs/img/mt-send-mpt-2-account-2.png
diff --git a/docs/img/tut-send-mpt-2-authorize-mpt.png b/docs/img/mt-send-mpt-2-authorize-mpt.png
similarity index 100%
rename from docs/img/tut-send-mpt-2-authorize-mpt.png
rename to docs/img/mt-send-mpt-2-authorize-mpt.png
diff --git a/docs/img/tut-send-mpt-3-send-mpt.png b/docs/img/mt-send-mpt-3-send-mpt.png
similarity index 100%
rename from docs/img/tut-send-mpt-3-send-mpt.png
rename to docs/img/mt-send-mpt-3-send-mpt.png
diff --git a/docs/img/tut-send-mpt-4-get-mpts.png b/docs/img/mt-send-mpt-4-get-mpts.png
similarity index 100%
rename from docs/img/tut-send-mpt-4-get-mpts.png
rename to docs/img/mt-send-mpt-4-get-mpts.png
diff --git a/docs/img/mt-send-xrp-1-xrpl-base-module.png b/docs/img/mt-send-xrp-1-xrpl-base-module.png
new file mode 100644
index 00000000000..1b795370ec8
Binary files /dev/null and b/docs/img/mt-send-xrp-1-xrpl-base-module.png differ
diff --git a/docs/img/mt-send-xrp-2-named-accounts.png b/docs/img/mt-send-xrp-2-named-accounts.png
new file mode 100644
index 00000000000..e729fcebaac
Binary files /dev/null and b/docs/img/mt-send-xrp-2-named-accounts.png differ
diff --git a/docs/img/mt-send-xrp-3-transferred-xrp.png b/docs/img/mt-send-xrp-3-transferred-xrp.png
new file mode 100644
index 00000000000..0adf64dd03c
Binary files /dev/null and b/docs/img/mt-send-xrp-3-transferred-xrp.png differ
diff --git a/docs/img/mt-send-xrp-4-account2-send-xrp.png b/docs/img/mt-send-xrp-4-account2-send-xrp.png
new file mode 100644
index 00000000000..8ed9efc9a96
Binary files /dev/null and b/docs/img/mt-send-xrp-4-account2-send-xrp.png differ
diff --git a/docs/img/mt-send-xrp-5-gather-account-info.png b/docs/img/mt-send-xrp-5-gather-account-info.png
new file mode 100644
index 00000000000..685af4282fd
Binary files /dev/null and b/docs/img/mt-send-xrp-5-gather-account-info.png differ
diff --git a/docs/img/mt-time-escrow-1-empty-form.png b/docs/img/mt-time-escrow-1-empty-form.png
new file mode 100644
index 00000000000..3d84544e152
Binary files /dev/null and b/docs/img/mt-time-escrow-1-empty-form.png differ
diff --git a/docs/img/mt-time-escrow-2-form-with-accounts.png b/docs/img/mt-time-escrow-2-form-with-accounts.png
new file mode 100644
index 00000000000..880d1df5257
Binary files /dev/null and b/docs/img/mt-time-escrow-2-form-with-accounts.png differ
diff --git a/docs/img/mt-time-escrow-3-create-escrow.png b/docs/img/mt-time-escrow-3-create-escrow.png
new file mode 100644
index 00000000000..6cc01698fd7
Binary files /dev/null and b/docs/img/mt-time-escrow-3-create-escrow.png differ
diff --git a/docs/img/mt-time-escrow-4-fulfill-escrow.png b/docs/img/mt-time-escrow-4-fulfill-escrow.png
new file mode 100644
index 00000000000..91a8cb0c14a
Binary files /dev/null and b/docs/img/mt-time-escrow-4-fulfill-escrow.png differ
diff --git a/docs/img/mt-time-escrow-5-get-escrows.png b/docs/img/mt-time-escrow-5-get-escrows.png
new file mode 100644
index 00000000000..2fa161fb7f0
Binary files /dev/null and b/docs/img/mt-time-escrow-5-get-escrows.png differ
diff --git a/docs/img/mt-time-escrow-6-cancel-escrow.png b/docs/img/mt-time-escrow-6-cancel-escrow.png
new file mode 100644
index 00000000000..2ce04b0597c
Binary files /dev/null and b/docs/img/mt-time-escrow-6-cancel-escrow.png differ
diff --git a/docs/img/quickstart-checks1.png b/docs/img/quickstart-checks1.png
deleted file mode 100644
index 908b0937a65..00000000000
Binary files a/docs/img/quickstart-checks1.png and /dev/null differ
diff --git a/docs/img/quickstart-checks2.png b/docs/img/quickstart-checks2.png
deleted file mode 100644
index 2274bf62436..00000000000
Binary files a/docs/img/quickstart-checks2.png and /dev/null differ
diff --git a/docs/img/quickstart-checks3.png b/docs/img/quickstart-checks3.png
deleted file mode 100644
index d9391107cf3..00000000000
Binary files a/docs/img/quickstart-checks3.png and /dev/null differ
diff --git a/docs/img/quickstart-checks4.png b/docs/img/quickstart-checks4.png
deleted file mode 100644
index f55b3f6b12c..00000000000
Binary files a/docs/img/quickstart-checks4.png and /dev/null differ
diff --git a/docs/img/quickstart-checks5.png b/docs/img/quickstart-checks5.png
deleted file mode 100644
index b05eec9f285..00000000000
Binary files a/docs/img/quickstart-checks5.png and /dev/null differ
diff --git a/docs/img/quickstart-checks6.png b/docs/img/quickstart-checks6.png
deleted file mode 100644
index 58fc506f6d3..00000000000
Binary files a/docs/img/quickstart-checks6.png and /dev/null differ
diff --git a/docs/img/quickstart-checks7.png b/docs/img/quickstart-checks7.png
deleted file mode 100644
index c6f64c8b9ff..00000000000
Binary files a/docs/img/quickstart-checks7.png and /dev/null differ
diff --git a/docs/img/quickstart-checks8.png b/docs/img/quickstart-checks8.png
deleted file mode 100644
index 943f2b7010e..00000000000
Binary files a/docs/img/quickstart-checks8.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow1.png b/docs/img/quickstart-escrow1.png
deleted file mode 100644
index 067534b3a15..00000000000
Binary files a/docs/img/quickstart-escrow1.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow2.png b/docs/img/quickstart-escrow2.png
deleted file mode 100644
index 8b069c248d3..00000000000
Binary files a/docs/img/quickstart-escrow2.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow3.png b/docs/img/quickstart-escrow3.png
deleted file mode 100644
index 54a5318a8df..00000000000
Binary files a/docs/img/quickstart-escrow3.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow4.png b/docs/img/quickstart-escrow4.png
deleted file mode 100644
index cc0c2e6fd29..00000000000
Binary files a/docs/img/quickstart-escrow4.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow5.png b/docs/img/quickstart-escrow5.png
deleted file mode 100644
index a768cd8d0ed..00000000000
Binary files a/docs/img/quickstart-escrow5.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow6.png b/docs/img/quickstart-escrow6.png
deleted file mode 100644
index 9ccfcfd8c42..00000000000
Binary files a/docs/img/quickstart-escrow6.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow7.png b/docs/img/quickstart-escrow7.png
deleted file mode 100644
index 79b9d6fd09c..00000000000
Binary files a/docs/img/quickstart-escrow7.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow8.png b/docs/img/quickstart-escrow8.png
deleted file mode 100644
index 650c9d96b7f..00000000000
Binary files a/docs/img/quickstart-escrow8.png and /dev/null differ
diff --git a/docs/img/quickstart-escrow9.png b/docs/img/quickstart-escrow9.png
deleted file mode 100644
index 69746a19230..00000000000
Binary files a/docs/img/quickstart-escrow9.png and /dev/null differ
diff --git a/docs/img/quickstart2.png b/docs/img/quickstart2.png
deleted file mode 100644
index ccc9170d6c7..00000000000
Binary files a/docs/img/quickstart2.png and /dev/null differ
diff --git a/docs/img/quickstart3.png b/docs/img/quickstart3.png
deleted file mode 100644
index 84be6261ef6..00000000000
Binary files a/docs/img/quickstart3.png and /dev/null differ
diff --git a/docs/img/quickstart4.png b/docs/img/quickstart4.png
deleted file mode 100644
index ceef3a7fb45..00000000000
Binary files a/docs/img/quickstart4.png and /dev/null differ
diff --git a/docs/img/quickstart5.png b/docs/img/quickstart5.png
deleted file mode 100644
index b9fe040b7fc..00000000000
Binary files a/docs/img/quickstart5.png and /dev/null differ
diff --git a/docs/img/quickstart6.png b/docs/img/quickstart6.png
deleted file mode 100644
index 2a87fc10f0d..00000000000
Binary files a/docs/img/quickstart6.png and /dev/null differ
diff --git a/docs/img/quickstart7.png b/docs/img/quickstart7.png
deleted file mode 100644
index 36e3d103b60..00000000000
Binary files a/docs/img/quickstart7.png and /dev/null differ
diff --git a/docs/img/uc-mpt1-t-bill-account-configuration.png b/docs/img/uc-mpt1-t-bill-account-configuration.png
index eae66e8e3f8..7d16d036edd 100644
Binary files a/docs/img/uc-mpt1-t-bill-account-configuration.png and b/docs/img/uc-mpt1-t-bill-account-configuration.png differ
diff --git a/docs/tutorials/javascript/index.md b/docs/tutorials/javascript/index.md
index d2b871fef24..8972852dbc7 100644
--- a/docs/tutorials/javascript/index.md
+++ b/docs/tutorials/javascript/index.md
@@ -27,7 +27,7 @@ To get started:
`npm install xrpl`
-- Clone or download the [Sample modules](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/).
+Download and expand the [Payment Modular Tutorial Samples](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
## Tutorial Modules
diff --git a/docs/tutorials/javascript/send-payments/create-accounts-send-xrp.md b/docs/tutorials/javascript/send-payments/create-accounts-send-xrp.md
index 45d017cdaaa..9c5ff887a8b 100644
--- a/docs/tutorials/javascript/send-payments/create-accounts-send-xrp.md
+++ b/docs/tutorials/javascript/send-payments/create-accounts-send-xrp.md
@@ -1,11 +1,8 @@
---
-html: create-accounts-send-xrp-using-javascript.html
-parent: send-payments-using-javascript.html
seo:
description: Create two accounts and transfer XRP between them.
labels:
- Accounts
- - Quickstart
- Transaction Sending
- XRP
---
@@ -19,7 +16,7 @@ This example shows how to:
When you create an account, you receive a public/private key pair offline. Your account does not appear on the ledger until it is funded with XRP. This example shows how to create accounts for Testnet, but not how to create an account that you can use on Mainnet.
-[](/docs/img/quickstart2.png)
+[](/docs/img/mt-send-xrp-1-xrpl-base-module.png)
## Prerequisites
@@ -29,613 +26,549 @@ To get started, create a new folder on your local disk and install the JavaScrip
npm install xrpl
```
-Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/) archive.
+Download and expand the [Payment Modular Tutorial Samples](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
-{% admonition type="info" name="Note" %}Without the Quickstart Samples, you will not be able to try the examples that follow. {% /admonition %}
+{% admonition type="info" name="Note" %}Without the Payment Modular Tutorials Samples, you will not be able to try the examples that follow. {% /admonition %}
## Usage
-
-
-
-
To get test accounts:
1. Open `1.get-accounts-send-xrp.html` in a browser
2. Choose **Testnet** or **Devnet**.
-3. Click **Get New Standby Account**.
-4. Click **Get New Operational Account.**
-5. Copy and paste the **Seeds** field in a persistent location, such as a Notepad, so that you can reuse the accounts after reloading the form.
+3. Click **Get New Account 1**.
+4. Click **Get New Account 2.**
+5. Optionally fill in **Account 1 Name** and **Account 2 Name**.
-[](/docs/img/quickstart3.png)
+The name fields are there for you to create an arbitrary label to make the account easier to recognize when switching back and forth than the 34 character account address. For example, I might name the accounts after my friends _Alfredo_ and _Binti_. The name is a local value that is never sent to the XRPL server.
-You can transfer XRP between your new accounts. Each account has its own fields and buttons.
+[](/docs/img/mt-send-xrp-2-named-accounts.png)
-
-
-
+To transfer XRP from Account 1 to Account 2:
-To transfer XRP from the Standby account to the Operational account:
+1. Click the **Account 1** radio button. The information about Account 1 populates the uneditable fields of the form.
+2. Enter the **Amount** of XRP to send.
+2. Copy and paste the **Account 2 Address** value to the **Destination** field.
+3. Click **Send XRP** to transfer XRP from Account 1 to Account 2.
-1. On the Standby (left) side of the form, enter the **Amount** of XRP to send.
-2. Copy and paste the **Operational Account** field to the Standby **Destination** field.
-3. Click **Send XRP>** to transfer XRP from the standby account to the operational account
+The **Results** field shows the change in balance in each of the accounts. Note that sending the XRP cost an additional .000001 XRP as the transfer fee. The transfer fee is small enough to be no burden for legitimate users, but is there to stop spammers from making DDS attacks against the XRP Ledger (sending millions of false transactions will quickly add up to real money).
-To transfer XRP from the Operational account to the Standby account:
+[](/docs/img/mt-send-xrp-3-transferred-xrp.png)
-1. On the Operational (right) side of the form, enter the **Amount** of XRP to send.
-2. Copy and paste the **Standby Account** field to the Operational **Destination** field.
-3. Click **<Send XRP** to transfer XRP from the Operational account to the Standby account.
+Click **Account 2** to see its XRP balance.
-[](/docs/img/quickstart4.png)
+To transfer XRP from Account 2 back to Account 1:
-# Code Walkthrough
+1. Click the **Account 2** radio button.
+2. Enter the **Amount** of XRP to send.
+3. Copy and paste the **Account 1 Address** value to the **Destination** field.
+4. Click **Send XRP** to transfer XRP from Account 1 to Account 2.
+5. Click the **Account 1** radio button to see its new XRP balance.
-You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/)in the source repository for this website.
-## ripplex-1-send-xrp.js
+[](/docs/img/mt-send-xrp-4-account2-send-xrp.png)
-This example can be used with any XRP Ledger network, _Testnet_, or _Devnet_. You can update the code to choose different or additional XRP Ledger networks.
+## Gather and Distribute Account Information
-### getNet()
-
+For most exercises, it's fine if you want to create a new account. If want to use the same account in another exercise, you can gather the information from both accounts to the **Result** field to paste into the next form.
-```javascript
-// ******************************************************
-// ************* Get the Preferred Network **************
-// ******************************************************
+1. Click **Gather Account Info**.
+2. Copy the name, address, and seed values from the **Result** field.
- function getNet() {
-```
+[](/docs/img/mt-send-xrp-5-gather-account-info.png)
-This function uses brute force `if` statements to discover the selected network instance and return the URI.
+3. Go to the next modular tutorial form.
+4. Paste the values in the **Result** field.
+5. Click **Distribute Account Info** to populate all of the Account 1 and Account 2 fields.
-```javascript
- let net
- if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233"
- if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233"
- return net
-} // End of getNet()
-```
+## Getting the XRP Balance
-### getAccount(type)
-
+The **XRP Balance** field is automatically updated when you choose **Account 1** or **Account 2**. If you send XRP to an account from another application and you want to see the result, you can click **Get XRP Balance** at any time to see the currently available XRP.
-```javascript
-// *******************************************************
-// ************* Get Account *****************************
-// *******************************************************
+## Getting the Token Balance
-async function getAccount(type) {
-```
+You can see the balance of all issued currencies, MPTs, and other tokens by clicking **Get Token Balance**. You can issue and send tokens in many of the modular tutorials that build off the XRPL Base Module.
-Get the selected ledger.
+# Code Walkthrough
-```javascript
- let net = getNet()
-```
+You can download the [Payment Modular Tutorials](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) from the source repository for this website.
-Instantiate a client.
+## account-support.js
-```javascript
- const client = new xrpl.Client(net)
-```
+This file contains the functions all of the modular examples use to create, use, and reuse accounts.
-Use the _results_ variable to capture progress information.
+### getNet()
-```javascript
- results = 'Connecting to ' + net + '....'
-```
-Use the default faucet using a _null_ value.
+This function can be used with _Testnet_, or _Devnet_. It allows you to select between them with a radio button to set the _net_ variable with the server URL.
```javascript
- let faucetHost = null
+function getNet() {
+ let net
+ if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233/"
+ if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233/"
+ return net
+} // End of getNet()
```
+### getAccount()
-Report progress in the appropriate results field.
+The `getAccount()` function uses the faucet host to fund a new account wallet
```javascript
- if (type == 'standby') {
- standbyResultField.value = results
- } else {
- operationalResultField.value = results
- }
+async function getAccount() {
```
-Connect to the server.
+Get the selected network, create a new client, and connect to the XRPL serever.
```javascript
+ let net = getNet()
+ const client = new xrpl.Client(net)
await client.connect()
-
- results += '\nConnected, funding wallet.'
- if (type == 'standby') {
- standbyResultField.value = results
- } else {
- operationalResultField.value = results
- }
-
-```
-
-Create and fund a test account.
-
-```javascript
- const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet
-
- results += '\nGot a wallet.'
- if (type == 'standby') {
- standbyResultField.value = results
- } else {
- operationalResultField.value = results
- }
+ resultField.value = `===Getting Account===\n\nConnected to ${net}.`
```
-Get the current XRP balance for the account.
+Request a new wallet funded with play-money XRP for experimentation.
```javascript
- const my_balance = (await client.getXrpBalance(my_wallet.address))
-```
-
-If this is a standby account, populate the standby account fields.
-
-```javascript
- if (type == 'standby') {
- standbyAccountField.value = my_wallet.address
- standbyPubKeyField.value = my_wallet.publicKey
- standbyPrivKeyField.value = my_wallet.privateKey
- standbyBalanceField.value = (await client.getXrpBalance(my_wallet.address))
- standbySeedField.value = my_wallet.seed
- results += '\nStandby account created.'
- standbyResultField.value = results
-```
-
-Otherwise, populate the operational account fields.
-
-```javascript
- } else {
- operationalAccountField.value = my_wallet.address
- operationalPubKeyField.value = my_wallet.publicKey
- operationalPrivKeyField.value = my_wallet.privateKey
- operationalSeedField.value = my_wallet.seed
- operationalBalanceField.value = (await client.getXrpBalance(my_wallet.address))
- results += '\nOperational account created.'
- operationalResultField.value = results
+ try {
+ let faucetHost = null
+ const my_wallet = (await client.fundWallet(null, { faucetHost})).wallet
+ const newAccount = [my_wallet.address, my_wallet.seed]
+ return (newAccount)
}
```
-Insert the seed values for both accounts as they are created to the **Seeds** field as a convenience. You can copy the values and store them offline. When you reload this form or another in this tutorial, copy and paste them into the **Seeds** field to retrieve the accounts with the `getAccountsFromSeeds()` function.
+Catch and report any errors.
```javascript
- seeds.value = standbySeedField.value + '\n' + operationalSeedField.value
+ catch (error) {
+ console.error('Error getting account:', error);
+ results = `\n===Error: ${error.message}===\n`
+ resultField.value += results
+ throw error; // Re-throw the error to be handled by the caller
+ }
```
-Disconnect from the XRP ledger.
+Disconnect from the XRPL server and return the address and seed information.
```javascript
client.disconnect()
+ return (newAccount)
} // End of getAccount()
```
-### Get Accounts from Seeds
+### getNewAccount1() and getNewAccount2()
+
+These are wrapper functions that call the getAccount() function, then populate the account address and account seed fields for Account1 or Account2, respectively.
```javascript
-// *******************************************************
-// ********** Get Accounts from Seeds ********************
-// *******************************************************
+async function getNewAccount1() {
+ account1address.value = "=== Getting new account. ===\n\n"
+ account1seed.value = ""
+ const accountInfo= await getAccount()
+ account1address.value = accountInfo[0]
+ account1seed.value = accountInfo[1]
+}
+
-async function getAccountsFromSeeds() {
+async function getNewAccount2() {
+ account2address.value = "=== Getting new account. ===\n\n"
+ account2seed.value = ""
+ const accountInfo= await getAccount()
+ account2address.value = accountInfo[0]
+ account2seed.value = accountInfo[1]
+}
```
-Connect to the selected network.
+### getAccountFromSeed()
+
+This function uses an existing seed value to access the client information from the XRP Ledger, then return the account address.
```javascript
- let net = getNet()
+async function getAccountFromSeed(my_seed) {
+ const net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
await client.connect()
- results += '\nConnected, finding wallets.\n'
- standbyResultField.value = results
+ let results = '===Finding wallet.===\n\n'
+ resultField.value = results
+ try {
+ const wallet = xrpl.Wallet.fromSeed(my_seed)
+ const address = wallet.address
+ results += "===Wallet found.===\n\n"
+ results += "Account address: " + address + "\n\n"
+ resultField.value = results
+ return (address)
+ }
```
-
-Parse the **Seeds** field.
+Catch and report any errors.
```javascript
- var lines = seeds.value.split('\n')
-```
+ catch (error) {
+ console.error('===Error getting account from seed:', error);
+ results += `\nError: ${error.message}\n`
+ resultField.value = results
+ throw error; // Re-throw the error to be handled by the caller
+ }
+ ```
-Get the `standby_wallet` based on the seed in the first line. Get the `operational_wallet` based on the seed in the second line.
+ Disconnect from the XRP Ledger and return the .
-```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(lines[0])
- const operational_wallet = xrpl.Wallet.fromSeed(lines[1])
+ ```javascript
+ finally {
+ await client.disconnect();
+ }
+} // End of getAccountFromSeed()
```
+### getAccountFromSeed1 and getAccountFromSeed2
-Get the current XRP balances for the accounts.
+These wrapper functions populate the Account1 Address or Account2 address from a seed value, respectively.
```javascript
- const standby_balance = (await client.getXrpBalance(standby_wallet.address))
- const operational_balance = (await client.getXrpBalance(operational_wallet.address))
+async function getAccountFromSeed1() {
+ account1address.value = await getAccountFromSeed(account1seed.value)
+}
+
+async function getAccountFromSeed2() {
+ account2address.value = await getAccountFromSeed(account2seed.value)
+}
```
-Populate the fields for the standby and operational accounts.
+### gatherAccountInfo()
+
+This local function copies the name, account, and seed values for Account1 and Account2 and displays the information in the **Result** field. You can then copy the information to reuse in another modular tutorial.
```javascript
- standbyAccountField.value = standby_wallet.address
- standbyPubKeyField.value = standby_wallet.publicKey
- standbyPrivKeyField.value = standby_wallet.privateKey
- standbySeedField.value = standby_wallet.seed
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
-
- operationalAccountField.value = operational_wallet.address
- operationalPubKeyField.value = operational_wallet.publicKey
- operationalPrivKeyField.value = operational_wallet.privateKey
- operationalSeedField.value = operational_wallet.seed
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
+function gatherAccountInfo() {
+ let accountData = account1name.value + "\n" + account1address.value + "\n" + account1seed.value + "\n"
+ accountData += account2name.value + "\n" + account2address.value + "\n" + account2seed.value
+ resultField.value = accountData
+}
```
-Disconnect from the XRP Ledger.
+### distributeAccountInfo()
+
+This local function parses structured account information from the **Result** field and distributes it to the corresponding account fields. It is the counterpart to the gatherAccountInfo() utility. The purpose is to let you continue to use the same accounts in all of the modular examples. If you have information that doesn't perfectly conform, you can still use this utility to populate the fields with the information that does fit the format.
```javascript
- client.disconnect()
-} // End of getAccountsFromSeeds()
+function distributeAccountInfo() {
+ let accountInfo = resultField.value.split("\n")
+ account1name.value = accountInfo[0]
+ account1address.value = accountInfo[1]
+ account1seed.value = accountInfo[2]
+ account2name.value = accountInfo[3]
+ account2address.value = accountInfo[4]
+ account2seed.value = accountInfo[5]
+}
```
-### Send XRP
+### populate1() and populate2
+
+These local functions populate the active form fields with values for their correesponding accounts.
```javascript
-// *******************************************************
-// ******************** Send XRP *************************
-// *******************************************************
+function populate1() {
+ accountNameField.value = account1name.value
+ accountAddressField.value = account1address.value
+ accountSeedField.value = account1seed.value
+ getXrpBalance()
+}
-async function sendXRP() {
+function populate2() {
+ accountNameField.value = account2name.value
+ accountAddressField.value = account2address.value
+ accountSeedField.value = account2seed.value
+ getXrpBalance()
+}
```
-Connect to your selected ledger.
+### getXrpBalance()
+
+Connect to the XRP Ledger, send a `getXrpBalance()` request for the current acitve account, then display it in the **XRP Balance Field**.
```javascript
- results = "Connecting to the selected ledger.\n"
- standbyResultField.value = results
- let net = getNet()
- results = 'Connecting to ' + getNet() + '....'
+async function getXrpBalance() {
+ const net = getNet()
const client = new xrpl.Client(net)
await client.connect()
-
- results += "\nConnected. Sending XRP.\n"
- standbyResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const sendAmount = standbyAmountField.value
-
- results += "\nstandby_wallet.address: = " + standby_wallet.address
- standbyResultField.value = results
-```
-
-Prepare the transaction. This is a Payment transaction from the standby address to the operational address.
+ let results = `\n===Getting XRP balance...===\n\n`
+ resultField.value = results
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const balance = await client.getXrpBalance(wallet.address)
+ results += accountNameField.value + " current XRP balance: " + balance + "\n\n"
+ xrpBalanceField.value = await client.getXrpBalance(accountAddressField.value)
+ resultField.value = results
+ }
+ ```
-The _Payment_ transaction expects the XRP to be expressed in drops, or 1/millionth of an XRP. You can use the `xrpToDrops()` method to convert the send amount for you (which beats having to type an extra 6 zeroes to send 1 XRP).
+ Catch any errors and disconnect from the XRP Ledger.
-```javascript
- const prepared = await client.autofill({
- "TransactionType": "Payment",
- "Account": standby_wallet.address,
- "Amount": xrpl.xrpToDrops(sendAmount),
- "Destination": standbyDestinationField.value
- })
+ ```javascript
+ catch (error) {
+ console.error('Error getting XRP balance:', error);
+ results += `\nError: ${error.message}\n`
+ resultField.value = results
+ throw error; // Re-throw the error to be handled by the caller
+ }
+ finally {
+ // Disconnect from the client
+ await client.disconnect();
+ }
```
+### getTokenBalance()
-Sign the prepared transaction.
+Get the balance of all tokens for the current active account. This is a function that is used frequently in other modular tutorials that deal with currencies other than XRP.
-```
-const signed = standby_wallet.sign(prepared)
+```javascript
+async function getTokenBalance() {
```
-Submit the transaction and wait for the results.
+Connect with the network.
-```
-const tx = await client.submitAndWait(signed.tx_blob)
+```javascript
+ let net = getNet()
+ const client = new xrpl.Client(net)
+ await client.connect()
+ let results = `===Connected to ${net}.===\n===Getting account token balance...===\n\n`
+ resultField.value += results
```
-Request the balance changes caused by the transaction and report the results.
+Send a request to get the account balance, then wait for the results.
+```javascript
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const balance = await client.request({
+ command: "gateway_balances",
+ account: wallet.address,
+ ledger_index: "validated",
+ })
+ results = accountNameField.value + "\'s token balance(s): " + JSON.stringify(balance.result, null, 2) + "\n"
+ resultField.value += results
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
+ }
```
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyResultField.value = results
-
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- client.disconnect()
-} // End of sendXRP()
-```
-
-### Reciprocal Transactions
-For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
-// **********************************************************************
-// ****** Reciprocal Transactions ***************************************
-// **********************************************************************
-
-// *******************************************************
-// ********* Send XRP from Operational account ***********
-// *******************************************************
-
-async function oPsendXRP() {
-
- results = "Connecting to the selected ledger.\n"
- operationalResultField.value = results
- let net = getNet()
- results = 'Connecting to ' + getNet() + '....'
- const client = new xrpl.Client(net)
- await client.connect()
-
- results += "\nConnected. Sending XRP.\n"
- operationalResultField.value = results
-
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const sendAmount = operationalAmountField.value
-
- results += "\noperational_wallet.address: = " + operational_wallet.address
- operationalResultField.value = results
-
-// ---------------------------------------------------------- Prepare transaction
- const prepared = await client.autofill({
- "TransactionType": "Payment",
- "Account": operational_wallet.address,
- "Amount": xrpl.xrpToDrops(operationalAmountField.value),
- "Destination": operationalDestinationField.value
- })
-
-// ---------------------------------------------------- Sign prepared instructions
- const signed = operational_wallet.sign(prepared)
-
-// ------------------------------------------------------------ Submit signed blob
- const tx = await client.submitAndWait(signed.tx_blob)
-
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- operationalResultField.value = results
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
-
- client.disconnect()
-} // End of oPsendXRP()
+
+ catch (error) {
+ console.error('Error getting token balance:', error);
+ results = `\nError: ${error.message}\n`
+ resultField.value += results
+ throw error; // Re-throw the error to be handled by the caller
+ }
+ finally {
+ // Disconnect from the client
+ await client.disconnect();
+ }
+}
```
-## 1.get-accounts-send-xrp.html
+## base-module.html
Create a standard HTML form to send transactions and requests, then display the results.
```html
-
- Token Test Harness
+
+ XRPL Base Module
-
-
-
-
-
-
+
+
+
+
+
+
-
-
Token Test Harness
+
+
XRPL Base Module
-
+
+
```
diff --git a/docs/tutorials/javascript/send-payments/create-conditional-escrows.md b/docs/tutorials/javascript/send-payments/create-conditional-escrows.md
index 0d38cb71d32..310d3174c0a 100644
--- a/docs/tutorials/javascript/send-payments/create-conditional-escrows.md
+++ b/docs/tutorials/javascript/send-payments/create-conditional-escrows.md
@@ -1,13 +1,12 @@
---
-html: create-conditional-escrows-using-javascript.html
-parent: send-payments-using-javascript.html
seo:
description: Create, finish, or cancel condition-based escrow transactions.
labels:
- Accounts
- - Quickstart
+ - Modular Tutorials
- Transaction Sending
- XRP
+ - Escrow
---
# Create Conditional Escrows Using JavaScript
@@ -19,12 +18,12 @@ This example shows how to:
3. Cancel a conditional escrow transaction.
-[](/docs/img/conditional-escrow1.png)
+[](/docs/img/mt-conditional-escrow-1-empty-form.png)
## Prerequisites
-Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/) archive.
+Download and expand the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
## Usage
@@ -34,632 +33,543 @@ You create a condition-based escrow using a fulfillment code associated with a
Install `five-bells-condition`:
-1. In a terminal window, navigate to your local `Quickstart` directory (for convenience).
+1. In a terminal window, navigate to your chosen local directory.
2. Enter the command `npm install five-bells-condition`.
To create a condition/fulfillment pair:
-1. In a terminal window, navigate to your `Quickstart` directory.
+1. In a terminal window, navigate to your chosen local directory.
2. Enter the command `node getConditionAndFulfillment.js`.
3. Copy and save the generated Condition and Fulfillment pair.
-[](/docs/img/conditional-escrow2.png)
+[](/docs/img/mt-conditional-escrow-2-getConditionAndFulfillment.png)
To get test accounts:
-1. Open `9.escrow-condition.html` in a browser
-2. Choose **Testnet** or **Devnet**.
-3. Get test accounts.
- 1. If you have existing account seeds
- 1. Paste account seeds in the **Seeds** field.
- 2. Click **Get Accounts from Seeds**.
- 2. If you do not have account seeds:
- 1. Click **Get New Standby Account**.
- 2. Click **Get New Operational Account**.
+1. Open `create-conditional-escrow.html` in a browser
+2. Get test accounts.
+ 1. If you copied the gathered information from another tutorial:
+ 1. Paste the gathered information to the **Result** field.
+ 2. Click **Distribute Account Info**.
+ 2. If you have an existing account seed:
+ 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field.
+ 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**.
+ 2. If you do not have existing accounts:
+ 1. Click **Get New Account 1**.
+ 2. Click **Get New Account 2**.
-[](/docs/img/conditional-escrow3.png)
+[](/docs/img/mt-conditional-escrow-3-form-with-accounts.png)
-### Create Conditional Escrow:
+### Create Conditional Escrow
-
-
-
-
-When you create a conditional escrow, you need to specify the amount you want to reserve and the `Condition` value you generated above. You can also set a cancel date and time, after which the escrow is no longer available.
+When you create a conditional escrow, you need to specify the amount you want to reserve and the `Condition` value you generated above. You can also set a cancel date and time, after which the escrow is no longer available. For testing, the **Cancel** time is in seconds: in practice, you might set a **Cancel** time in days, weeks, months, or years.
To create a conditional escrow:
1. Enter an **Amount** to transfer.
-2. Copy the **Operational Account** value.
-3. Paste it in the **Destination Account** field.
+3. Enter the **Destination** field (for example, use Account 2 Address).
4. Enter the **Escrow Condition** value.
-5. Enter the **Escrow Cancel (seconds)** value.
+5. Enter the **Escrow Cancel (seconds)** value.
6. Click **Create Escrow**.
-7. Copy and save the _Sequence Number_ of the escrow called out in the **Standby Result** field.
+7. Copy and save the _Sequence Number_ of the escrow called out in the **Results** field.
The escrow is created on the XRP Ledger instance, reserving your requested XRP amount plus the transaction cost.
When you create an escrow, capture and save the _Sequence Number_ so that you can use it to finish the escrow transaction.
-[](/docs/img/conditional-escrow4.png)
+[](/docs/img/mt-conditional-escrow-4-escrow-create.png)
## Finish Conditional Escrow
Any account can finish the conditional escrow any time before the _Escrow Cancel_ time. Following on the example above, you can use the _Sequence Number_ to finish the transaction once the Escrow Cancel time has passed.
-To finish a time-based escrow:
+To finish a conditional escrow:
-1. Paste the sequence number in the Operational account **Escrow Sequence Number** field.
-2. Enter the `Fulfillment` code for the `Condition`.
-3. Click **Finish Conditional Escrow**.
+1. Enter the **Escrow Condition** code for the escrow.
+2. Enter the corresponding **Escrow Fulfillment** code.
+3. Enter the **Escrow Owner** (the account address of the account that created the escrow).
+4. Enter the sequence number in the **Escrow Sequence Number** field.
+5. Click **Finish Escrow**.
-The transaction completes and balances are updated for both the Standby and Operational accounts.
+The transaction is completed and balances adjusted for both accounts.
-[](/docs/img/conditional-escrow5.png)
+[](/docs/img/mt-conditional-escrow-5-escrow-fulfill.png)
## Get Escrows
-Click **Get Escrows** for either the Standby account or the Operational account to see their current list of escrows.
+Click **Get Escrows** to see the current list of escrows generated by or destined for the current account.
## Cancel Escrow
-When the Escrow Cancel time passes, the escrow is no longer available to the recipient. The initiator of the escrow can reclaim the XRP, less the transaction fees. Any account can cancel an escrow once the cancel time has elapsed. Accounts that try to cancel the transaction prior to the **Escrow Cancel** time are charged the nominal transaction cost (12 drops), but the actual escrow cannot be cancelled until after the Escrow Cancel time.
+When the Escrow Cancel time passes, the escrow is no longer available to the recipient. The initiator of the escrow can reclaim the XRP, less the transaction fees. Any account can cancel an escrow once the cancel time has elapsed. Accounts that try to cancel the transaction prior to the **Escrow Cancel** time are charged the nominal transaction cost (typically 12 drops), but the actual escrow cannot be cancelled until after the Escrow Cancel time.
+
+To cancel an expired escrow:
+
+1. Enter the sequence number in the **Escrow Sequence Number** field.
+2. Click **Cancel Escrow**.
## Oh No! I Forgot to Save the Sequence Number!
If you forget to save the sequence number, you can find it in the escrow transaction record.
-1. Create a new escrow as described in [Create Escrow](#create-escrow), above.
+1. If needed, create a new escrow as described in [Create Escrow](#create-escrow), above.
2. Click **Get Escrows** to get the escrow information.
3. Copy the _PreviousTxnID_ value from the results.
- 
-4. Paste the _PreviousTxnID_ in the **Transaction to Look Up** field.
- 
+ [](/docs/img/mt-conditional-escrow-6-get-escrows.png)
+4. Paste the _PreviousTxnID_ in the **Transaction** field.
5. Click **Get Transaction**.
-6. Locate the _Sequence_ value in the results.
- 
+6. Locate the _ModifiedNode.PreviousFields.Sequence_ value in the results.
+ [](/docs/img/mt-conditional-escrow-7-sequence-value.png)
# Code Walkthrough
-You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/)in the source repository for this website.
-
-## getConditionAndFulfillment.js
-
-To generate a condition/fulfillment pair, use Node.js to run the `getConditionAndFulfillment.js` script.
-
-```javascript
-function getConditionAndFulfillment() {
-```
-
-Instantiate the `five-bells-condition` and `crypto` libraries.
-
-```javascript
- const cc = require('five-bells-condition')
- const crypto = require('crypto')
-```
-
-Create a random 32-byte seed string.
+Download the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
-```javascript
- const preimageData = crypto.randomBytes(32)
-```
+## five-bells.cjs
-Create a fulfillment object.
+To generate a condition/fulfillment pair, use Node.js to run the `five-bells.js` script.
```javascript
- const fulfillment = new cc.PreimageSha256()
-```
+const cc = require('five-bells-condition')
+const crypto = require('crypto')
-Generate a fulfillment code.
+// 1. Generate a random 32-byte seed
+const preimageData = crypto.randomBytes(32)
-```javascript
- fulfillment.setPreimage(preimageData)
-```
+// 2. Create a PreimageSha256 fulfillment object
+const fulfillment = new cc.PreimageSha256()
-Generate the condition value based on the fulfillment value.
-
-```javascript
- const condition = fulfillment.getConditionBinary().toString('hex').toUpperCase()
-```
+// 3. Set the preimage
+fulfillment.setPreimage(preimageData)
-Return the condition.
+// 4. Generate the condition (binary)
+const conditionBinary = fulfillment.getConditionBinary()
-```javascript
- console.log('Condition:', condition)
-```
+// 5. Generate the fulfillment (binary)
+const fulfillmentBinary = fulfillment.serializeBinary()
-Convert the fulfillment code to a hexadecimal string.
+// Convert to hex for easier use
+const conditionHex = conditionBinary.toString('hex').toUpperCase()
+const fulfillmentHex = fulfillmentBinary.toString('hex').toUpperCase()
-```javascript
- const fulfillment_hex = fulfillment.serializeBinary().toString('hex').toUpperCase()
+console.log('Condition (hex):', conditionHex)
+console.log('Fulfillment (hex):', fulfillmentHex)
```
-Return the fulfillment code. Keep it secret until you want to finish the escrow.
+## create-conditional-escrow.js
-```javascript
- console.log('Fulfillment:', fulfillment_hex)
-}
-getConditionAndFulfillment()
-```
-## ripplex9-escrow-condition.js
+### createConditionalEscrow()
-
-### Create Conditional Escrow
+Connect to the ledger and get the account wallet.
```javascript
async function createConditionalEscrow() {
-```
-
-Connect to your preferred ledger.
-
-```javascript
- results = "Connecting to the selected ledger.\n"
- standbyResultField.value = results
- let net = getNet()
- results = "Connecting to " + net + "....\n"
+ let net = getNet()
const client = new xrpl.Client(net)
await client.connect()
-
- results += "Connected. Creating conditional escrow.\n"
- standbyResultField.value = results
-```
-
-Instantiate the standby and operational wallets
-
-```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
-```
-
-Capture the amount to send in the escrow.
-
-```javascript
- const sendAmount = standbyAmountField.value
-```
-
-Update the results field.
-
-```javascript
- results += "\nstandby_wallet.address: = " + standby_wallet.address
- standbyResultField.value = results
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const sendAmount = amountField.value
+ let results = `===Connected to ${net}===\n===Creating conditional escrow.===\n\n`
+ resultField.value = results
```
-Create a date value and add your requested number of seconds.
+Prepare the cancel date by adding the number of seconds in the **Escrow Cancel Date** field to the current date and time. In practice, the cancel date might be in days, weeks, months, or years. Using seconds allows you to test scenarios with expired escrows.
```javascript
let escrow_cancel_date = new Date()
- escrow_cancel_date = addSeconds(parseInt(standbyEscrowCancelDateField.value))
+ escrow_cancel_date = addSeconds(parseInt(escrowCancelDateField.value))
```
-Prepare the `EscrowCreate` transaction.
+Prepare the transaction object.
```javascript
const escrowTx = await client.autofill({
"TransactionType": "EscrowCreate",
- "Account": standby_wallet.address,
+ "Account": wallet.address,
"Amount": xrpl.xrpToDrops(sendAmount),
- "Destination": standbyDestinationField.value,
+ "Destination": destinationField.value,
"CancelAfter": escrow_cancel_date,
- "Condition": standbyEscrowConditionField.value
+ "Condition": escrowConditionField.value
})
```
-Sign the transaction.
+Sign the prepared transaction object.
```javascript
- const signed = standby_wallet.sign(escrowTx)
+ const signed = wallet.sign(escrowTx)
```
-Submit the transaction and wait for the results.
+Submit the signed object and wait for the results.
```javascript
const tx = await client.submitAndWait(signed.tx_blob)
```
-Report the results and update balance fields.
+Report the results, parsing the _Sequence Number_ for later use.
```javascript
- results += "\nSequence Number (Save!): " + JSON.stringify(tx.result.Sequence)
- results += "\n\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- standbyResultField.value = results
+ results = "\n=== *** Sequence Number (Save!): " + tx.result.tx_json.Sequence
+ results += "\n\n===Balance changes===\n" +
+ JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
+ resultField.value += results
```
-Disconnect from the XRPL
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
-client.disconnect()
-
-} // End of createTimeEscrow()
+ catch (error) {
+ results += "\n===Error: " + error.message
+ resultField.value = results
+ }
+ finally {
+ // -------------------------------------------------------- Disconnect
+ client.disconnect()
+ }// End of createTimeEscrow()
```
-### Finish Conditional Escrow
+### finishConditionalEscrow()
-Finish the escrow by submitting the condition and fulfillment codes.
+Connect to the ledger and get the account wallet from the account seed.
```javascript
async function finishConditionalEscrow() {
-```
-
-Connect to your preferred XRP Ledger instance.
-
-```javascript
- results = "Connecting to the selected ledger.\n"
- operationalResultField.value = results
let net = getNet()
- results += 'Connecting to ' + getNet() + '....'
const client = new xrpl.Client(net)
await client.connect()
- results += "\nConnected. Finishing escrow.\n"
- operationalResultField.value = results
-```
-
-Get the standby and operational account wallets.
-
-```javascript
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const sendAmount = operationalAmountField.value
-
- results += "\noperational_wallet.address: = " + operational_wallet.address
- operationalResultField.value = results
+ let results = `===Connected to ${net}===\n===Fulfilling conditional escrow.===\n`
+ resultField.value = results
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
```
-Prepare the transaction.
+Prepare the transaction object.
```javascript
const prepared = await client.autofill({
"TransactionType": "EscrowFinish",
- "Account": operationalAccountField.value,
- "Owner": standbyAccountField.value,
- "OfferSequence": parseInt(operationalEscrowSequenceField.value),
- "Condition": standbyEscrowConditionField.value,
- "Fulfillment": operationalFulfillmentField.value
+ "Account": accountAddressField.value,
+ "Owner": escrowOwnerField.value,
+ "OfferSequence": parseInt(escrowSequenceNumberField.value),
+ "Condition": escrowConditionField.value,
+ "Fulfillment": escrowFulfillmentField.value
})
```
-Sign the transaction.
+Sign the prepared transaction object.
```javascript
-
- const signed = operational_wallet.sign(prepared)
+ const signed = wallet.sign(prepared)
```
-Submit the transaction and wait for the results.
+Submit the signed transaction and wait for the results.
```javascript
const tx = await client.submitAndWait(signed.tx_blob)
```
-Report the results.
+Report the results
```javascript
- results += "\nBalance changes: " +
+ results = "\n===Balance changes===" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- operationalResultField.value = results
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
+ resultField.value += results
```
-Disconnect from the XRPL.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- client.disconnect()
-
-} // End of finishEscrow()
+ catch (error) {
+ results += "\n===Error: " + error.message + ".===\n"
+ resultField.value = results
+ }
+ finally {
+ // -------------------------------------------------------- Disconnect
+ client.disconnect()
+ }
```
-
-## 9.escrow-condition.html
+## create-conditional-escrow.html
```html
-
- Conditional Escrow Test Harness
+
+ Create a Conditional Escrow
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
Conditional Escrow Test Harness
+
+
Create a Conditional Escrow
-
+
+
```
diff --git a/docs/tutorials/javascript/send-payments/create-offers.md b/docs/tutorials/javascript/send-payments/create-offers.md
index 665b00707f2..9c9073fd2f0 100644
--- a/docs/tutorials/javascript/send-payments/create-offers.md
+++ b/docs/tutorials/javascript/send-payments/create-offers.md
@@ -17,61 +17,64 @@ This example shows how to:
4. Cancel an unsettled offer.
-[](/docs/img/module-create-offer.png)
+[](/docs/img/mt-create-offers-1-empty-form-info.png)
-Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/) archive.
+Download and expand the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
-**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
+**Note:** Without the Modular Tutorial Samples, you will not be able to try the examples that follow.
## Usage
-
+
To get test accounts:
-1. Open `3a.CreateOffer.html` in a browser
-2. Choose **Testnet** or **Devnet**.
-3. Enter an **Account Name** for the left column. For example, _Standby_.
-4. Click **Get New Account** on the left.
-5. Enter an **Account Name** for the right column. For example, _Operational_.
-5. Click **Get New Account** on the right.
-6. Copy and paste the **Seeds** field in a persistent location, such as a Notepad, so that you can reuse the accounts after reloading the form.
+1. Open `create-offers.html` in a browser.
+2. Get test accounts.
+ 1. If you copied the gathered information from another tutorial:
+ 1. Paste the gathered information to the **Result** field.
+ 2. Click **Distribute Account Info**.
+ 2. If you have an existing account seed:
+ 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field.
+ 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**.
+ 2. If you do not have existing accounts:
+ 1. Click **Get New Account 1**.
+ 2. Click **Get New Account 2**.
-[](/docs/img/module-create-offer-get-accounts.png)
+[](/docs/img/mt-create-offers-2-form-with-account-info.png)
You can create and match offers from either account.
## Create Offer
-To create an offer to exchange XRP for an issued currency on the Standby (left) side:
+To create an offer to exchange XRP for an issued currency:
-1. Enter _XRP_ as the Taker Pays **Currency**.
-2. Enter the Taker Pays **Value** in drops. For example, _50000000_.
+1. Click **Account 1** or **Account 2**.
+2. Enter _XRP_ as the Taker Pays **Currency Code**.
+2. Enter the Taker Pays **Amount** in drops. For example, _50000000_.
3. Enter the Taker Gets **Currency**. For example, _USD_.
-4. Copy the left account (_Standby_) value to the Taker Gets **Issuer** field.
-5. Enter the Taker Gets **Value**. For example, _50_.
+4. Copy the current **Account Address** and paste it in the Taker Gets **Issuer** field.
+5. Enter the Taker Gets **Amount**. For example, _50_.
6. Click **Create Offer**.
-[](/docs/img/module-create-offer-xrp-for-usd.png)
+[](/docs/img/mt-create-offers-3-xrp-for-usd-offer.png)
-To create a complementary offer on the Operational (right) side:
+## Get Offers
-1. Enter the Taker Pays **Currency**. For example, _USD_.
-2. Copy the left (Standby) side **Account** string into the **Issuer** field.
-3. Enter the Taker Pays **Value**. For example, _50_.
-4. Enter _XRP_ as the Taker Gets **Currency**.
-5. Enter the Taker Gets **Value** in drops. For example, _50000000_.
-6. Click **Create Offer**.
+Click **Get Offers** to get a list of offers issued by the corresponding account.
-[](/docs/img/module-create-offer-xrp-for-usd2.png)
+[](/docs/img/mt-create-offers-3-xrp-for-usd-offer.png)
-## Get Offers
+## Create a Matching Offer
-Click **Get Offers** to get a list of offers issued by the corresponding account.
+1. Choose an account other than the Issuer. For example, **Account 2**.
+2. Enter _XRP_ as the Taker Gets **Currency Code**.
+3. Enter the Taker Gets **Amount**. For example, _50000000_.
+3. Enter the Taker Pays **Currency Code**, for example _USD_.
+4. Enter the Taker Pays **Issuer**. For example, the **Account 1 Address**.
+5. Enter the Taker Pays **Amount** For example, _50_.
+6. Click **Create Offer**.
-[](/docs/img/module-create-offer-get-offers.png)
+
+[](/docs/img/mt-create-offers-4-matching-offer.png)
## Cancel Offer
@@ -79,1012 +82,468 @@ To cancel an existing offer:
1. Enter the sequence number of the offer in the **Offer Sequence** field. To find the sequence number, you can click **Get Offers**, then look for the _Seq_ value for the offer you want to cancel.
-[](/docs/img/module-create-offer-cancel-offer.png)
+[](/docs/img/mt-create-offers-5-sequence-number.png)
2. Click **Cancel Offer**, then click **Get Offers** to show that the offer has been removed from the list of outstanding offers.
-[](/docs/img/module-create-offer-cancelled-offer.png)
+[](/docs/img/mt-create-offers-6-no-offers.png)
# Code Walkthrough
-You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} in the source repository for this website.
+You can download the [Payment Modular Tutorials](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) from the source repository for this website.
+
+## create-offer.js
-## ripplex3a-create-offers.js
+The functions in create-offer.html leverage functions from the base module. The functions that follow are solely focused on creating and handling offers.
### Create Offer
-Initialize variables for the _takerGets_ and _takerPays_ payload, and get the selected developer network instance.
+Connect to the XRP Ledger and get the account wallet.
-```js
+```javascript
async function createOffer() {
- let takerGets = ''
- let takerPays = ''
let net = getNet()
-```
-
-Get a client instance and connect to the XRP Ledger.
-
-```js
- let results = 'Connecting to ' + net + '....\n'
const client = new xrpl.Client(net)
await client.connect()
+ let results = `===Connected to ${net}, getting wallet....===\n`
+ resultField.value = results
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
```
-Get the wallets for both accounts.
-
-```js
- results += "Connected. Getting wallets.\n"
- standbyResultField.value = results
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- results += standbyNameField.value + " account address: " + standby_wallet.address + "\n"
- standbyResultField.value = results
-```
-
-If the currency for the "Taker Gets" side of the deal is XRP, you only need the value (amount) of XRP to request. If you are trading an issued currency, you need to capture the currency code, issuer account, and value.
-
-```js
- if (standbyTakerGetsCurrencyField.value == 'XRP') {
- takerGets = standbyTakerGetsValueField.value
- } else {
- takerGetsString = '{"currency": "' + standbyTakerGetsCurrencyField.value +'",\n' +
- '"issuer": "' + standbyTakerGetsIssuerField.value + '",\n' +
- '"value": "' + standbyTakerGetsValueField.value + '"}'
- takerGets = JSON.parse(takerGetsString)
- }
-```
-
-Similarly on the "Take Pays" side, you only need the value when trading XRP.
-
-```js
- if (standbyTakerPaysCurrencyField.value == 'XRP') {
- takerPays = standbyTakerPaysValueField.value
- } else {
- takerPaysString = '{"currency": "' + standbyTakerPaysCurrencyField.value + '",\n' +
- '"issuer": "' + standbyTakerPaysIssuerField.value + '",\n' +
- '"value": "' + standbyTakerPaysValueField.value + '"}'
- takerPays = JSON.parse(takerPaysString)
- }
-```
-
-Prepare the transaction.
-
-```js
- const prepared = await client.autofill({
- "TransactionType": "OfferCreate",
- "Account": standby_wallet.address,
- "TakerGets": takerGets,
- "TakerPays": takerPays
- })
- ```
-
- Sign the prepared instructions.
-
- ```js
- const signed = standby_wallet.sign(prepared)
- results += "\nSubmitting transaction...."
-```
+Gather the information for what the taker pays, and what the taker gets in return. If the **Currency Code** is _XRP_, the amount is equal to the value in the **Amount** field. Otherwise, the `takerGets` parameter is constructed as an array containing the currency code, issuer address, and the value in the amount field.
-Submit the signed transaction blob.
-
-```js
-const tx = await client.submitAndWait(signed.tx_blob)
-```
-
-Report the results and update XRP balances.
-
-```js
- results += tx.results + "\n"
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyResultField.value = results
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
-```
-
-Call the `getOffers` function to show the new offer.
-
-```js
- getOffers()
-```
-
-Disconnect from the XRP Ledger.
-
-```js
- client.disconnect()
-}
-```
-
-### Get Offers
-
-Connect to the XRP Ledger and get the wallet for the Standby (left) side of the Token Test Harness.
-
-```js
-async function getOffers() {
- let net = getNet()
- let results = 'Connecting to ' + net + '....\n'
- const client = new xrpl.Client(net)
- await client.connect()
- results += "Connected.\n"
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- results += standbyNameField.value + " acccount: " + standby_wallet.address
-```
-
-Label the offers section of the results
-
-```js
- results += '\n\n*** Offers ***\n'
-```
-
-Send the _account_offers_ request to the XRP Ledger. Capture the results.
-
-```js
+```javascript
try {
- const offers = await client.request({
- method: "account_offers",
- account: standby_wallet.address,
- ledger_index: "validated"
- })
- results += JSON.stringify(offers,null,2)
- } catch (err) {
- results += err
- }
-```
-
-Report the results and disconnect from the XRP Ledger.
-
-```js
- standbyResultField.value = results
- client.disconnect()
-}
-```
-
-### Cancel Offer
-
-Connect to the XRP Ledger and get the account wallets.
-
-```js
-
- async function cancelOffer() {
- let results = "Connecting to the selected ledger.\n"
- standbyResultField.value = results
- let net = getNet()
- results += 'Connecting to ' + net + '....\n'
- const client = new xrpl.Client(net)
- await client.connect()
-
- results += "Connected.\n"
- standbyResultField.value = results
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- results += "standby_wallet.address: = " + standby_wallet.address
- standbyResultField.value = results
-```
-
-Prepare the transaction. `The OfferSequence` is the `Seq` value in the response to the `account_offers` request.
-
-```js
- const prepared = await client.autofill({
- "TransactionType": "OfferCancel",
- "Account": standby_wallet.address,
- "OfferSequence": parseInt(standbyOfferSequenceField.value)
- })
-```
-
-Sign the prepared transaction.
-```js
- const signed = standby_wallet.sign(prepared)
-```
-
-Submit the transaction and wait for the results.
-
-```js
- const tx = await client.submitAndWait(signed.tx_blob)
-```
-
-Capture the balance changes and report the results.
-
-```js
- results += "\nBalance changes: \n" +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyResultField.value = results
-```
-
-Update the XRP balance.
-
-```js
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
-```
-
-Disconnect from the XRP Ledger.
-
-```js
- client.disconnect()
- }
-```
-
-### Reciprocal functions for the Operational (right) account.
-```js
- /***********************************
- ********* OP Create Offer *********
- **********************************/
-
- async function oPcreateOffer() {
- let takerGets = ''
- let takerPays = ''
-
- operationalResultField.value = ''
- let net = getNet()
- let results = 'Connecting to ' + net + '....\n'
- const client = new xrpl.Client(net)
- await client.connect()
-
- results += "Connected. Getting wallets.\n"
- operationalResultField.value = results
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- results += operationalNameField.value + " account address: " + operational_wallet.address + "\n"
- operationalResultField.value = results
-
-
- if (operationalTakerGetsCurrencyField.value == 'XRP') {
- takerGets = operationalTakerGetsValueField.value
+ if (getCurrencyField.value == 'XRP') {
+ takerGets = getAmountField.value
} else {
- takerGetsString = '{"currency": "' + operationalTakerGetsCurrencyField.value +'",\n' +
- '"issuer": "' + operationalTakerGetsIssuerField.value + '",\n' +
- '"value": "' + operationalTakerGetsValueField.value + '"}'
- takerGets = JSON.parse(takerGetsString)
+ takerGetsString = '{"currency": "' + getCurrencyField.value +'",\n' +
+ '"issuer": "' + getIssuerField.value + '",\n' +
+ '"value": "' + getAmountField.value + '"}'
+ takerGets = JSON.parse(takerGetsString)
}
+```
+
+The same logic is used to create the value for the `takerPays` parameter.
- if (operationalTakerPaysCurrencyField.value == 'XRP') {
- takerPays = operationalTakerPaysValueField.value
+```javascript
+ if (payCurrencyField.value == 'XRP') {
+ takerPays = xrpl.xrpToDrops(payAmountField.value)
} else {
- takerPaysString = '{"currency": "' + operationalTakerPaysCurrencyField.value + '",\n' +
- '"issuer": "' + operationalTakerPaysIssuerField.value + '",\n' +
- '"value": "' + operationalTakerPaysValueField.value + '"}'
+ takerPaysString = '{"currency": "' + payCurrencyField.value + '",\n' +
+ '"issuer": "' + payIssuerField.value + '",\n' +
+ '"value": "' + payAmountField.value + '"}'
takerPays = JSON.parse(takerPaysString)
}
-
- // -------------------------------------------------------- Prepare transaction
- const prepared = await client.autofill({
- "TransactionType": "OfferCreate",
- "Account": operational_wallet.address,
- "TakerGets": takerGets,
- "TakerPays": takerPays
- })
- // ------------------------------------------------- Sign prepared instructions
- const signed = operational_wallet.sign(prepared)
- results += "\nSubmitting transaction...."
- // -------------------------------------------------------- Submit signed blob
- const tx = await client.submitAndWait(signed.tx_blob)
-
- results += tx.results + "\n"
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- operationalResultField.value = results
-
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- getOffers()
- client.disconnect()
- } // End of oPcreateOffer()
-
- /***********************************
- ********** OP Get Offers ***********
- ***********************************/
-
-async function oPgetOffers() {
- let results = "Connecting to the selected ledger.\n"
- operationalResultField.value = results
- let net = getNet()
- results = 'Connecting to ' + net + '....\n'
- const client = new xrpl.Client(net)
- await client.connect()
-
- results += "Connected.\n"
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- results += operationalNameField.value + " account: " + operational_wallet.address
- operationalResultField.value = results
+ ```
- // -------------------------------------------------------- Prepare request
+Define the `OfferCreate` transaction, using the `takerPays` and `takerGets` parameters defined above.
- results += '\n\n*** Offers ***\n'
- let offers
- try {
- const offers = await client.request({
- method: "account_offers",
- account: operational_wallet.address,
- ledger_index: "validated"
- })
- results += JSON.stringify(offers,null,2)
- } catch (err) {
- results += err
- }
- results += JSON.stringify(offers,null,2)
- operationalResultField.value = results
- client.disconnect()
-}// End of oPgetOffers()
-
-/************************************
- ********** Op Cancel Offer *********
- ***********************************/
-
-async function oPcancelOffer() {
- let net = getNet()
- let results = 'Connecting to ' + net + '....\n'
- const client = new xrpl.Client(net)
- await client.connect()
-
- results += "Connected.\n"
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- results += "wallet.address: = " + operational_wallet.address
- operationalResultField.value = results
-
- // -------------------------------------------------------- Prepare transaction
-
- /* OfferSequence is the Seq value when you getOffers. */
+ ```javascript
const prepared = await client.autofill({
- "TransactionType": "OfferCancel",
- "Account": operational_wallet.address,
- "OfferSequence": parseInt(operationalOfferSequenceField.value)
-})
-
-// ------------------------------------------------- Sign prepared instructions
- const signed = operational_wallet.sign(prepared)
-
-// -------------------------------------------------------- Submit signed blob
- const tx = await client.submitAndWait(signed.tx_blob)
-
- results += "\nBalance changes: \n" + tx.result + "\n" +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- operationalResultField.value = results
-
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- client.disconnect()
-} // End of oPcancelOffer()
-```
-
-## ripplex3b-name-field-support.js
-
-When creating more complex transactions, it can be difficult to remember which account number was performing which part of the deal. To ease the mental burden, there is a new _Name_ field to facilitate working with use cases that typically involve more than two accounts. The account name is appended to the seed values, which makes them reusable and portable to other forms with name field support. To migrate an account, paste the seed value into the seeds field, add a period, then type the account name as a string with no spaces.
-
-With the exception of the changes that enable use of the Name field, the functions in this JavaScript file are identical to the functions found in `ripplex1-send-xrp.js`.
-
-
-```javascript
-### getNet()
-
- function getNet() {
-```
-
-This function uses brute force `if` statements to discover the selected network instance and return the URI.
-
-```javascript
- let net
- if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233"
- if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233"
- return net
-} // End of getNet()
-```
-
-### getAccount(type)
-
-
-```javascript
-// *******************************************************
-// ************* Get Account *****************************
-// *******************************************************
-
-async function getAccount(type) {
-```
-
-Get the selected ledger.
-
-```javascript
- let net = getNet()
-```
-
-Instantiate a client.
-
-```javascript
- const client = new xrpl.Client(net)
-```
-
-Use the _results_ variable to capture progress information.
-
-```javascript
- results = 'Connecting to ' + net + '....'
-```
-Use the default faucet using a _null_ value.
-
-```javascript
- let faucetHost = null
-```
-
-Report progress in the appropriate results field.
-
-```javascript
- if (type == 'standby') {
- standbyResultField.value = results
- } else {
- operationalResultField.value = results
- }
+ "TransactionType": "OfferCreate",
+ "Account": wallet.address,
+ "TakerGets": takerGets,
+ "TakerPays": takerPays
+ })
```
-Connect to the server.
+Sign and send the prepared transaction, and wait for the results.
```javascript
- await client.connect()
-
- results += '\nConnected, funding wallet.'
- if (type == 'standby') {
- standbyResultField.value = results
- } else {
- operationalResultField.value = results
- }
-
+ const signed = wallet.sign(prepared)
+ const tx = await client.submitAndWait(signed.tx_blob)
```
-Create and fund a test account.
+Request the token balance changes after the transaction.
```javascript
- const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet
-
- results += '\nGot a wallet.'
- if (type == 'standby') {
- standbyResultField.value = results
- } else {
- operationalResultField.value = results
- }
+ results = '\n\n===Offer created===\n\n' +
+ JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
+ resultField.value += results
```
-Get the current XRP balance for the account.
+Get the new XRP balance, reflecting the payments and transaction fees.
```javascript
- const my_balance = (await client.getXrpBalance(my_wallet.address))
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
```
-If this is a standby account, populate the standby account fields.
```javascript
- if (type == 'standby') {
- standbyAccountField.value = my_wallet.address
- standbyBalanceField.value = (await client.getXrpBalance(my_wallet.address))
- standbySeedField.value = my_wallet.seed
- results += '\nAccount created named ' + standbyNameField.value + '.'
- standbyResultField.value = results
+ getOffers()
```
-Otherwise, populate the operational account fields.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- } else {
- operationalAccountField.value = my_wallet.address
- operationalSeedField.value = my_wallet.seed
- operationalBalanceField.value = (await client.getXrpBalance(my_wallet.address))
- results += '\nAccount created named ' + operationalNameField.value + '.'
- operationalResultField.value = results
+ } catch (err) {
+ console.error('Error creating offer:', err);
+ results = `\nError: ${err.message}\n`
+ resultField.value += results
+ throw err; // Re-throw the error to be handled by the caller
}
+ finally {
+ // Disconnect from the client
+ client.disconnect()
+ })
```
-Insert the seed values and names for both accounts as they are created to the **Seeds** field as a convenience. You can copy the values and store them offline. When you reload this form or another in this tutorial, copy and paste them into the **Seeds** field to retrieve the accounts with the `getAccountsFromSeeds()` function.
-
-```javascript
- seeds.value = standbySeedField.value + "." + standbyNameField.value + '\n' +
- operationalSeedField.value + "." + operationalNameField.value
-```
-
-Disconnect from the XRP ledger.
-
-```javascript
- client.disconnect()
-} // End of getAccount()
-```
-
-### Get Accounts from Seeds
+### getOffers
-```javascript
-// *******************************************************
-// ********** Get Accounts from Seeds ********************
-// *******************************************************
-
-async function getAccountsFromSeeds() {
-```
+This function requests a list of all offers posted by an account.
-Connect to the selected network.
+Connect to the XRP Ledger and get the Account wallet.
```javascript
+async function getOffers() {
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
await client.connect()
- results += '\nConnected, finding wallets.\n'
- standbyResultField.value = results
-```
-
-Parse the **Seeds** field.
-
-```javascript
- var lines = seeds.value.split('\n')
- var first_line_value = lines[0]
- var first_line = first_line_value.split('.')
- var first_seed = first_line[0]
- var first_name = first_line[1]
-
- var second_line = lines[1].split('.')
- var second_seed = second_line[0]
- var second_name = second_line[1]
+ let results = `===Connected to ' + ${net}, getting offers....===\n`
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ resultField.value = results
```
-Get the `standby_wallet` based on the seed in the first line. Get the `operational_wallet` based on the seed in the second line.
+Send a request for all `account_offers` for the specified account address and report the results.
```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(lines[0])
- const operational_wallet = xrpl.Wallet.fromSeed(lines[1])
+ results += '\n\n*** Offers ***\n'
+ let offers
+ try {
+ offers = await client.request({
+ method: "account_offers",
+ account: wallet.address,
+ ledger_index: "validated"
+ })
+ results = JSON.stringify(offers, null, 2)
+ resultField.value += results
```
-Populate the fields for the standby and operational accounts.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- standbyAccountField.value = standby_wallet.address
- standbyNameField.value = first_name
- standbySeedField.value = first_seed
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
-
- operationalAccountField.value = operational_wallet.address
- operationalNameField.value = second_name
- operationalSeedField.value = second_seed
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
-```
-
-Disconnect from the XRP Ledger.
+ } catch (err) {
+ console.error('Error getting offers:', err);
+ results = `\nError: ${err.message}\n`
+ resultField.value += results
+ throw err; // Re-throw the error to be handled by the caller
+ }
+ finally {
+ client.disconnect()
+ }
-```javascript
- client.disconnect()
-} // End of getAccountsFromSeeds()
```
-### Send XRP
-
-```javascript
-// *******************************************************
-// ******************** Send XRP *************************
-// *******************************************************
+### cancelOffer()
-async function sendXRP() {
-```
+You can cancel an offer before it is matched with another offer.
-Connect to your selected ledger.
+Connect to the XRP Ledger and get the account wallet.
```javascript
- results = "Connecting to the selected ledger.\n"
- standbyResultField.value = results
+async function cancelOffer() {
let net = getNet()
- results = 'Connecting to ' + getNet() + '....'
const client = new xrpl.Client(net)
await client.connect()
-
- results += "\nConnected. Sending XRP.\n"
- standbyResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const sendAmount = standbyAmountField.value
-
- results += "\nstandby_wallet.address: = " + standby_wallet.address
- standbyResultField.value = results
-```
-
-Prepare the transaction. This is a Payment transaction from the standby address to the operational address.
-
-The _Payment_ transaction expects the XRP to be expressed in drops, or 1/millionth of an XRP. You can use the `xrpToDrops()` method to convert the send amount for you (which beats having to type an extra 6 zeroes to send 1 XRP).
-
-```javascript
- const prepared = await client.autofill({
- "TransactionType": "Payment",
- "Account": standby_wallet.address,
- "Amount": xrpl.xrpToDrops(sendAmount),
- "Destination": standbyDestinationField.value
- })
+ let results = `===Connected to ${net}, canceling offer.===\n`
+ resultField.value = results
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
```
-Sign the prepared transaction.
+Prepare the `OfferCancel` transaction, passing the account address of the account that created the offer and the `Sequence` of the offer.
```javascript
-const signed = standby_wallet.sign(prepared)
+ try {
+ const prepared = await client.autofill({
+ "TransactionType": "OfferCancel",
+ "Account": wallet.address,
+ "OfferSequence": parseInt(offerSequenceField.value)
+ })
```
-Submit the transaction and wait for the results.
+Sign and submit the transaction, then wait for the result.
```javascript
-const tx = await client.submitAndWait(signed.tx_blob)
+ const signed = wallet.sign(prepared)
+ const tx = await client.submitAndWait(signed.tx_blob)
```
-Request the balance changes caused by the transaction and report the results.
+Report the results.
```javascript
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyResultField.value = results
-
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- client.disconnect()
-} // End of sendXRP()
+ results += "\nOffer canceled. Balance changes: \n" +
+ JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
+ resultField.value = results
```
-### Reciprocal Transactions
-
-For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
-
-// *******************************************************
-// ********* Send XRP from Operational account ***********
-// *******************************************************
-
-async function oPsendXRP() {
-
- results = "Connecting to the selected ledger.\n"
- operationalResultField.value = results
- let net = getNet()
- results = 'Connecting to ' + getNet() + '....'
- const client = new xrpl.Client(net)
- await client.connect()
-
- results += "\nConnected. Sending XRP.\n"
- operationalResultField.value = results
-
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const sendAmount = operationalAmountField.value
-
- results += "\noperational_wallet.address: = " + operational_wallet.address
- operationalResultField.value = results
-
-// ---------------------------------------------------------- Prepare transaction
- const prepared = await client.autofill({
- "TransactionType": "Payment",
- "Account": operational_wallet.address,
- "Amount": xrpl.xrpToDrops(sendAmount),
- "Destination": operationalDestinationField.value
- })
-
-// ---------------------------------------------------- Sign prepared instructions
- const signed = operational_wallet.sign(prepared)
-
-// ------------------------------------------------------------ Submit signed blob
- const tx = await client.submitAndWait(signed.tx_blob)
-
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- operationalResultField.value = results
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
-
- client.disconnect()
-
-} // End of oPsendXRP()
+ }
+ catch (err) {
+ console.error('Error canceling offer:', err);
+ results = `\nError: ${err.message}\n`
+ resultField.value += results
+ throw err; // Re-throw the error to be handled by the caller
+ }
+ finally {
+ client.disconnect()
+ }
+}// End of cancelOffer()
```
-## 3a.CreateOffer.html
-
-This form includes the added account name fields, to allow you to swap in different accounts for a variety of use cases with a recognizable label for the seed and account values.
+## create-offer.html
```html
-
- Token Test Harness
+
+ Create Offers
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
Token Test Harness
+
+
+
+
+
+
+
+
Create Offers
-
+
+
```
diff --git a/docs/tutorials/javascript/send-payments/create-time-based-escrows.md b/docs/tutorials/javascript/send-payments/create-time-based-escrows.md
index ef7e7fb3720..1f0e9c132be 100644
--- a/docs/tutorials/javascript/send-payments/create-time-based-escrows.md
+++ b/docs/tutorials/javascript/send-payments/create-time-based-escrows.md
@@ -1,11 +1,8 @@
---
-html: create-time-based-escrows-using-javascript.html
-parent: send-payments-using-javascript.html
seo:
description: Create, finish, or cancel time-based escrow transactions.
labels:
- Accounts
- - Quickstart
- Transaction Sending
- XRP
---
@@ -20,49 +17,48 @@ This example shows how to:
3. Cancel an escrow payment and return the XRP to the sending account.
-[](/docs/img/quickstart-escrow1.png)
+[](/docs/img/mt-time-escrow-1-empty-form.png)
## Prerequisites
-Download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/).
+Download and expand the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
## Usage
To get test accounts:
-1. Open `8.escrow.html` in a browser
-2. Choose **Testnet** or **Devnet**.
-3. Get test accounts.
- 1. If you have existing account seeds
- 1. Paste account seeds in the **Seeds** field.
- 2. Click **Get Accounts from Seeds**.
- 2. If you do not have account seeds:
- 1. Click **Get New Standby Account**.
- 2. Click **Get New Operational Account**.
+1. Open `create-time-based-escrows.html` in a browser
+2. Get test accounts.
+ 1. If you copied the gathered information from another tutorial:
+ 1. Paste the gathered information to the **Result** field.
+ 2. Click **Distribute Account Info**.
+ 2. If you have an existing account seed:
+ 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field.
+ 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**.
+ 2. If you do not have existing accounts:
+ 1. Click **Get New Account 1**.
+ 2. Click **Get New Account 2**.
-[](/docs/img/quickstart-escrow2.png)
+[](/docs/img/mt-time-escrow-2-form-with-accounts.png)
## Create Escrow
-
-
-
-
You can create a time-based escrow with a minimum time to finish the escrow and a cancel time after which the funds in escrow are no longer available to the recipient. This is a test harness: while a practical scenario might express time in days or weeks, this form lets you set the finish and cancel times in seconds so that you can quickly run through a variety of scenarios. (There are 86,400 seconds in a day, if you want to play with longer term escrows.)
To create a time-based escrow:
-1. Enter an **Amount** to transfer.
-2. Copy the **Operational Account** value.
-3. Paste it in the **Destination Account** field.
-4. Set the **Escrow Finish (seconds)** value. For example, enter _10_.
-5. Set the **Escrow Cancel (seconds)** value. For example, enter _120_.
-6. Click **Create Escrow**.
+1. Enter an **Amount** to transfer. For example, _10_.
+2. Enter the **Destination**. (For example, the Account 2 address.)
+4. Set the **Escrow Finish Time** value, in seconds. For example, enter _10_.
+5. Set the **Escrow Cancel Time** value, in seconds. For example, enter _120_.
+6. Click **Create Time-based Escrow**.
7. Copy the _Sequence Number_ of the escrow called out in the **Standby Result** field.
-The escrow is created on the XRP Ledger instance, reserving 100 XRP plus the transaction cost. When you create an escrow, capture and save the **Sequence Number** so that you can use it to finish the escrow transaction.
+The escrow is created on the XRP Ledger instance, reserving 10 XRP plus the transaction cost. When you create an escrow, capture and save the **Sequence Number** so that you can use it to finish the escrow transaction.
+
+The escrow finish and cancel times are expressed in seconds here to let you experiment with scenarios where the escrows are outside the time constraints. In practice, escrow times might be expressed in days, weeks, months, or years.
-[](/docs/img/quickstart-escrow3.png)
+[](/docs/img/mt-time-escrow-3-create-escrow.png)
## Finish Escrow
@@ -71,11 +67,12 @@ The recipient of the XRP held in escrow can finish the transaction any time with
To finish a time-based escrow:
1. Paste the sequence number in the Operational account **Escrow Sequence Number** field.
-2. Click **Finish Escrow**.
+2. Copy and paste the address that created the escrow in the **Escrow Owner** field.
+2. Click **Finish Time-based Escrow**.
The transaction completes and balances are updated for both the Standby and Operational accounts.
-[](/docs/img/quickstart-escrow4.png)
+[](/docs/img/mt-time-escrow-4-fulfill-escrow.png)
## Get Escrows
@@ -83,9 +80,9 @@ Click **Get Escrows** for either the Standby account or the Operational account
For the purposes of this tutorial, follow the steps in [Create Escrow](#create-escrow), above, to create a new escrow transaction, perhaps setting **Escrow Cancel (seconds)** field to _600_ seconds to give you extra time to explore. Remember to capture the _Sequence Number_ from the transaction results.
-Click **Get Escrows** for both the Standby and the Operational account. The `account_info` request returns the same `account_object` for both accounts, demonstrating the link between the accounts created by the escrow transaction.
+Click **Get Escrows**.
-[](/docs/img/quickstart-escrow5.png)
+[](/docs/img/mt-time-escrow-5-get-escrows.png)
## Cancel Escrow
@@ -96,30 +93,30 @@ You can wait the allotted time for the escrow you created in the previous step,
To cancel an expired escrow:
-1. Enter the sequence number in the Standby **Escrow Sequence Number** field.
+1. Enter the sequence number in the **Escrow Sequence Number** field.
+2. Enter the address of the account that created the escrow in the **Escrow Owner** field.
2. Click **Cancel Escrow**.
-The funds are returned to the Standby account, less the initial transaction fee.
+The funds are returned to the owner account, less the initial transaction fee.
-[](/docs/img/quickstart-escrow6.png)
+[](/docs/img/mt-time-escrow-6-cancel-escrow.png)
## Oh No! I Forgot to Save the Sequence Number!
If you forget to save the sequence number, you can find it in the escrow transaction record.
-1. Create a new escrow as described in [Create Escrow](#create-escrow), above.
+1. If needed, create a new escrow as described in [Create Escrow](#create-escrow), above.
2. Click **Get Escrows** to get the escrow information.
3. Copy the _PreviousTxnID_ value from the results.
- 
-4. Paste the _PreviousTxnID_ in the **Transaction to Look Up** field.
- 
+ [](/docs/img/mt-conditional-escrow-6-get-escrows.png)
+4. Paste the _PreviousTxnID_ in the **Transaction** field.
5. Click **Get Transaction**.
-6. Locate the _Sequence_ value in the results.
- 
+6. Locate the _ModifiedNode.PreviousFields.Sequence_ value in the results.
+ [](/docs/img/mt-conditional-escrow-7-sequence-value.png)
# Code Walkthrough
-You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/)in the source repository for this website.
+Download and expand the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
## ripple8-escrow.js
@@ -162,7 +159,7 @@ Return the result.
### Create Time-based Escrow
```javascript
-async function createTimeEscrow() {
+async function createTimeBasedEscrow() {
```
Instantiate two new date objects, then set the dates to the current date plus the set number of seconds for the finish and cancel dates.
@@ -170,200 +167,144 @@ Instantiate two new date objects, then set the dates to the current date plus th
```javascript
let escrow_finish_date = new Date()
let escrow_cancel_date = new Date()
- escrow_finish_date = addSeconds(parseInt(standbyEscrowFinishDateField.value))
- escrow_cancel_date = addSeconds(parseInt(standbyEscrowCancelDateField.value))
+ escrow_finish_date = addSeconds(parseInt(escrowFinishTimeField.value))
+ escrow_cancel_date = addSeconds(parseInt(escrowCancelTimeField.value))
```
-Connect to the ledger.
+Connect to the ledger and get the account wallet.
```javascript
- results = "Connecting to the selected ledger.\n"
- standbyResultField.value = results
let net = getNet()
- results = "Connecting to " + net + "....\n"
const client = new xrpl.Client(net)
await client.connect()
- results += "Connected. Creating time-based escrow.\n"
- standbyResultField.value = results
+ let results = `===Connected to ${net}.===\n\n===Creating time-based escrow.===\n`
+ resultField.value = results
```
-Get the wallet information based on the account seed values.
+Define the transaction object.
```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const sendAmount = standbyAmountField.value
- results += "\nstandby_wallet.address: = " + standby_wallet.address
- standbyResultField.value = results
-```
-
-Define the `EscrowCreate` transaction, automatically filling values in common fields.
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const sendAmount = amountField.value
+ const escrowTx = await client.autofill({
+ "TransactionType": "EscrowCreate",
+ "Account": wallet.address,
+ "Amount": xrpl.xrpToDrops(sendAmount),
+ "Destination": destinationField.value,
+ "FinishAfter": escrow_finish_date,
+ "CancelAfter": escrow_cancel_date
+ })
-```javascript
- const escrowTx = await client.autofill({
- "TransactionType": "EscrowCreate",
- "Account": standby_wallet.address,
- "Amount": xrpl.xrpToDrops(sendAmount),
- "Destination": standbyDestinationField.value,
- "FinishAfter": escrow_finish_date,
- "CancelAfter": escrow_cancel_date
- })
-```
+ ```
-Sign the escrow transaction definition.
+ Sign the prepared transaction object.
```javascript
- const signed = standby_wallet.sign(escrowTx)
+ const signed = wallet.sign(escrowTx)
+ }
```
-Submit the transaction.
+Submit the signed transaction object and wait for the results.
```javascript
- const tx = await client.submitAndWait(signed.tx_blob)
+ const tx = await client.submitAndWait(signed.tx_blob)
```
Report the results.
```javascript
- results += "\nSequence Number (Save!): " + JSON.stringify(tx.result.Sequence)
- results += "\n\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- standbyResultField.value = results
+ results += "\n===Success! === *** Save this sequence number: " + tx.result.tx_json.Sequence
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
+ resultField.value = results
+ }
```
-Disconnect from the XRP Ledger.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- client.disconnect()
-} // End of createTimeEscrow()
+ catch (error) {
+ results += "\n===Error: " + error.message
+ resultField.value = results
+ }
+ finally {
+ client.disconnect()
+ }
```
+
### Finish Time-based Escrow
```javascript
async function finishEscrow() {
```
-Connect to the XRP Ledger and get the account wallets.
+Connect to the XRP Ledger.
```javascript
- results = "Connecting to the selected ledger.\n"
- operationalResultField.value = results
let net = getNet()
- results = 'Connecting to ' + getNet() + '....'
const client = new xrpl.Client(net)
await client.connect()
-
- results += "\nConnected. Finishing escrow.\n"
- operationalResultField.value = results
-
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const sendAmount = operationalAmountField.value
-
- results += "\noperational_wallet.address: = " + operational_wallet.address
- operationalResultField.value = results
+ let results = `===Connected to ${net}. Finishing escrow.===\n`
+ resultField.value = results
```
Define the transaction. The _Owner_ is the account that created the escrow. The _OfferSequence_ is the sequence number of the escrow transaction. Automatically fill in the common fields for the transaction.
```javascript
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
const prepared = await client.autofill({
"TransactionType": "EscrowFinish",
- "Account": operationalAccountField.value,
- "Owner": standbyAccountField.value,
- "OfferSequence": parseInt(operationalEscrowSequenceField.value)
+ "Account": accountAddressField.value,
+ "Owner": escrowOwnerField.value,
+ "OfferSequence": parseInt(escrowSequenceNumberField.value)
})
```
Sign the transaction definition.
```javascript
- const signed = operational_wallet.sign(prepared)
+ const signed = wallet.sign(prepared)
```
Submit the signed transaction to the XRP ledger.
```javascript
-
const tx = await client.submitAndWait(signed.tx_blob)
```
Report the results.
```javascript
- results += "\nBalance changes: " +
+ results += "\n===Balance changes===" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- operationalResultField.value = results
-
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
-```
-
-Disconnect from the XRP Ledger.
-
-```javascript
- client.disconnect()
-} // End of finishEscrow()
-```
-
-### Get Standby Escrows
-
-Get the escrows associated with the Standby account.
-
-```javascript
-async function getStandbyEscrows() {
-```
-
-Connect to the network. The information you are looking for is public information, so there is no need to instantiate your wallet.
-
-```javascript
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
-
- await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
-
- results= "\nGetting standby account escrows...\n"
-```
-
-Create the `account_objects` request. Specify that you want objects of the type _escrow_.
-
-```javascript
- const escrow_objects = await client.request({
- "id": 5,
- "command": "account_objects",
- "account": standbyAccountField.value,
- "ledger_index": "validated",
- "type": "escrow"
- })
+ resultField.value = results
```
-Report the results.
+Update the **XRP Balance** field.
```javascript
- results += JSON.stringify(escrow_objects.result, null, 2)
- standbyResultField.value = results
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
```
-Disconnect from the XRP Ledger
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- client.disconnect()
-} // End of getStandbyEscrows()
+ catch (error) {
+ results += "\n===Error: " + error.message + "==="
+ resultField.value = results
+ }
+ finally {
+ client.disconnect()
+ }
```
-### Get Operational Escrows
+### Get Escrows
-This function is the same as `getStandbyEscrows()`, but for the Operational account.
+Get the escrows created by or destined to the current account.
```javascript
-async function getOperationalEscrows() {
+async function getEscrows() {
```
Connect to the network. The information you are looking for is public information, so there is no need to instantiate your wallet.
@@ -371,40 +312,43 @@ Connect to the network. The information you are looking for is public informatio
```javascript
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
-
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- results= "\nGetting operational account escrows...\n"
+ await client.connect()
+ let results = `\n===Connected to ${net}.\nGetting account escrows.===\n`
+ resultField.value = results
```
Create the `account_objects` request. Specify that you want objects of the type _escrow_.
```javascript
- const escrow_objects = await client.request({
- "id": 5,
- "command": "account_objects",
- "account": operationalAccountField.value,
- "ledger_index": "validated",
- "type": "escrow"
- })
+ try {
+ const escrow_objects = await client.request({
+ "id": 5,
+ "command": "account_objects",
+ "account": accountAddressField.value,
+ "ledger_index": "validated",
+ "type": "escrow"
+ })
```
Report the results.
```javascript
- results += JSON.stringify(escrow_objects.result, null, 2)
- operationalResultField.value = results
+ results += JSON.stringify(escrow_objects.result, null, 2)
+ resultField.value = results
+ }
```
+Catch and report any errors, then disconnect from the XRP Ledger.
-Disconnect from the XRP Ledger instance.
```javascript
- client.disconnect()
-} // End of getOperationalEscrows()
+ catch (error) {
+ results += "\nError: " + error.message
+ resultField.value = results
+ }
+ finally {
+ client.disconnect()
+ }
+}
```
### Get Transaction Info
@@ -418,412 +362,378 @@ Connect to the XRP Ledger.
```javascript
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
-
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- results= "\nGetting transaction information...\n"
+ await client.connect()
+ let results = `\n===Connected to ${net}.===\n===Getting transaction information.===\n`
+ resultField.value = results
```
Prepare and send the transaction information request. The only required parameter is the transaction ID.
```javascript
- const tx_info = await client.request({
- "id": 1,
- "command": "tx",
- "transaction": operationalTransactionField.value,
- })
+ try {
+ const tx_info = await client.request({
+ "id": 1,
+ "command": "tx",
+ "transaction": transactionField.value,
+ })
```
Report the results.
```javascript
- results += JSON.stringify(tx_info.result, null, 2)
- operationalResultField.value = results
+ results += JSON.stringify(tx_info.result, null, 2)
+ resultField.value = results
+ }
```
-Disconnect from the XRP Ledger instance.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- client.disconnect()
+ catch (error) {
+ results += "\nError: " + error.message
+ resultField.value = results
+ }
+ finally {
+ client.disconnect()
+ }
} // End of getTransaction()
```
### Cancel Escrow
-Cancel an escrow after it passes the expiration date.
+Cancel an escrow after it passes the expiration date and time.
```javascript
async function cancelEscrow() {
```
-Connect to the XRP Ledger instance.
+Connect to the XRP Ledger instance and get the account wallet.
```javascript
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
-
- await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
-```
-
-Get the account wallets.
-
-```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
+ await client.connect()
+ let results = `\n===Connected to ${net}. Cancelling escrow.===`
+ resultField.value = results
```
-Prepare the EscrowCancel transaction.
+Prepare the EscrowCancel transaction, passing the escrow owner and offer sequence values.
```javascript
- const prepared = await client.autofill({
- "TransactionType": "EscrowCancel",
- "Account": standby_wallet.address,
- "Owner": standbyAccountField.value,
- "OfferSequence": parseInt(standbyEscrowSequenceNumberField.value)
- })
+ try {
+ const prepared = await client.autofill({
+ "TransactionType": "EscrowCancel",
+ "Account": accountAddressField.value,
+ "Owner": escrowOwnerField.value,
+ "OfferSequence": parseInt(escrowSequenceNumberField.value)
+ })
```
Sign the transaction.
+
```javascript
- const signed = standby_wallet.sign(prepared)
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const signed = wallet.sign(prepared)
```
Submit the transaction and wait for the response.
``` javascript
- const tx = await client.submitAndWait(signed.tx_blob)
+ const tx = await client.submitAndWait(signed.tx_blob)
```
Report the results.
```javascript
- results += "\nBalance changes: " +
- JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
- standbyResultField.value = results
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
+ results += "\n===Balance changes: " +
+ JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
+ resultField.value = results
+)
```
-Disconnect from the XRP Ledger instance.
+Catch and report any errors, then disconnect from the XRP Ledger instance.
```javascript
- client.disconnect()
+ }
+ catch (error) {
+ results += "\n===Error: " + error.message
+ resultField.value = results
+ }
+ finally {
+ client.disconnect()
+ }
}
```
-## 8.escrow.html
+## create-time-escrow.html
```html
-
- Time-based Escrow Test Harness
+
+ Create a Time-based Escrow
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
Time-based Escrow Test Harness
+
+
Create a Time-based Escrow
-
+
+
```
diff --git a/docs/tutorials/javascript/send-payments/create-trust-line-send-currency.md b/docs/tutorials/javascript/send-payments/create-trust-line-send-currency.md
index adae0c244cb..9ebaa3f4746 100644
--- a/docs/tutorials/javascript/send-payments/create-trust-line-send-currency.md
+++ b/docs/tutorials/javascript/send-payments/create-trust-line-send-currency.md
@@ -1,12 +1,9 @@
---
-html: create-trustline-send-currency-using-javascript.html
-parent: send-payments-using-javascript.html
seo:
description: Create Trust Lines and send currency.
labels:
- Cross-Currency
- Payments
- - Quickstart
- Tokens
---
@@ -14,797 +11,470 @@ labels:
This example shows how to:
-1. Configure accounts to allow transfer of funds to third party accounts.
-2. Set a currency type for transactions.
-3. Create a trust line between the standby account and the operational account.
-4. Send issued currency between accounts.
-5. Display account balances for all currencies.
+1. Create a trust line between two accounts.
+2. Send issued currency between accounts.
+3. Display account balances for all currencies.
-[](/docs/img/quickstart5.png)
+[](/docs/img/mt-send-currency-1-empty-form-info.png)
-You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/) archive to try each of the samples in your own browser.
+You can download the [Payment Modular Tutorials](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) from the source repository for this website.
-{% admonition type="info" name="Note" %}Without the Quickstart Samples, you will not be able to try the examples that follow. {% /admonition %}
+{% admonition type="info" name="Note" %}Without the Payment modular tutorials, you will not be able to try the examples that follow. {% /admonition %}
## Usage
-Open the Token Test Harness and get accounts:
+Open the Send Currency test harness and get accounts:
-1. Open `2.create-trustline-send-currency.html` in a browser.
+1. Open `send-currency.html` in a browser.
2. Get test accounts.
- 1. If you have existing account seeds
- 1. Paste account seeds in the **Seeds** field.
- 2. Click **Get Accounts from Seeds**.
- 2. If you do not have account seeds:
- 1. Click **Get New Standby Account**.
- 2. Click **Get New Operational Account**.
+ 1. If you copied the gathered information from another tutorial:
+ 1. Paste the gathered information to the **Result** field.
+ 2. Click **Distribute Account Info**.
+ 2. If you have an existing account seed:
+ 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field.
+ 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**.
+ 2. If you do not have existing accounts:
+ 1. Click **Get New Account 1**.
+ 2. Click **Get New Account 2**.
+
+[](/docs/img/mt-send-currency-2-distribute-accounts.png)
+
+If you want an account to be able to transfer issued currency to accounts other than the issuer, the issuer account must be configured to allow rippling. See _Issuer_ in the [Configuring Accounts](../../../concepts/accounts/configuring-accounts.md#issuer) topic.
+
+Accounts can always transfer currency tokens back to the original issuer.
## Create Trust Line
-
-
-
+In order to trade standard tokens, you must first establish a trust line from the receiving account to the issuing account.
To create a trust line between accounts:
-1. Enter a [currency code](https://www.iban.com/currency-codes) in the **Currency** field.
-2. Enter the maximum transfer limit in the **Amount** field.
-3. Enter the destination account value in the **Destination** field.
-4. Click **Create Trustline**.
+1. Click **Account 2** to populate the uneditable fields in the form.
+2. Enter a [currency code](https://www.iban.com/currency-codes) in the **Currency Code** field.
+3. Enter the maximum transfer limit in the **Amount** field.
+4. Copy and paste the **Account 1 Address** value to the **Issuer** field.
+5. Click **Create Trust Line**.
-[](/docs/img/quickstart6.png)
+[](/docs/img/mt-send-currency-3-create-trustline.png)
## Send an Issued Currency Token
To transfer an issued currency token, once you have created a trust line:
-1. Enter the **Amount**.
-2. Enter the **Destination**.
-3. Enter the **Currency** type.
+1. Click **Account 1**.
+3. Enter the **Currency Code**.
+4. Copy and paste the **Account 1 Address** to the **Issuer** field.
+4. Enter the **Amount** of issued currency to send.
+2. Copy and paste the **Account 2 Address** to the **Destination** field.
4. Click **Send Currency**.
-[](/docs/img/quickstart7.png)
-
-# Code Walkthrough
-
-You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/quickstart/js/) archive to try each of the samples in your own browser.
-
-## ripplex2-send-currency.js
-
+[](/docs/img/mt-send-currency-4-send-currency.png)
-### Configure Account
+## Get the Current Token Balance
-When transferring fiat currency, the actual transfer of funds is not simultaneous, as it is with XRP. If currency is transferred to a third party for a different currency, there can be a devaluation of the currency that impacts the originating account. To avoid this situation, this up and down valuation of currency, known as _rippling_, is not allowed by default. Currency transferred from one account can only be transferred back to the same account. To enable currency transfer to third parties, you need to set the `rippleDefault` value to true. The Token Test Harness provides a checkbox to enable or disable rippling.
-
-```javascript
-// *******************************************************
-// **************** Configure Account ********************
-// *******************************************************
-
-async function configureAccount(type, defaultRippleSetting) {
-```
-
-Connect to the ledger
-
-```javascript
- let net = getNet()
- let resultField = 'standbyResultField'
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- await client.connect()
- results += '\nConnected, finding wallet.'
-```
+To see the balances for all issued tokens for an account.
-Get the account wallets.
+1. Click **Account 1** or **Account 2**.
+2. Click **Get Token Balance**.
-```
-if (type=='standby') {
- my_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
-} else {
- my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- resultField = 'operationalResultField'
-}
-results += '\nRipple Default Setting: ' + defaultRippleSetting
-resultField.value = results
-```
+The balance for an issuing account is shown as an obligation.
-Prepare the transaction. If the `rippleDefault` argument is true, set the `asfDefaultRipple` flag. If it is false, clear the `asfDefaultRipple` flag.
+[](/docs/img/mt-send-currency-5-issuer-token-balance.png)
-```javascript
- let settings_tx = {}
- if (defaultRippleSetting) {
- settings_tx = {
- "TransactionType": "AccountSet",
- "Account": my_wallet.address,
- "SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
- }
- results += '\n Set Default Ripple flag.'
- } else {
- settings_tx = {
- "TransactionType": "AccountSet",
- "Account": my_wallet.address,
- "ClearFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
- }
- results += '\n Clear Default Ripple flag.'
- }
- results += '\nSending account setting.'
- resultField.value = results
-```
+The balance for a holder account is shown as an asset.
-Auto-fill the default values for the transaction.
+[](/docs/img/mt-send-currency-6-holder-token-balance.png)
-```javascript
- const prepared = await client.autofill(settings_tx)
-```
-
-Sign the transaction.
-
-```javascript
- const signed = my_wallet.sign(prepared)
-```
-
-Submit the transaction and wait for the result.
+# Code Walkthrough
-```javascript
- const result = await client.submitAndWait(signed.tx_blob)
-```
+You can download the [Payment Modular Tutorials](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) from the source repository for this website.
-Report the result.
+## send-currency.js
-```javascript
- if (result.result.meta.TransactionResult == "tesSUCCESS") {
- results += '\nAccount setting succeeded.'
- document.getElementById(resultField).value = results
- } else {
- throw 'Error sending transaction: ${result}'
- results += '\nAccount setting failed.'
- resultField.value = results
- }
- client.disconnect()
-} // End of configureAccount()
-```
+There are two asynchronous functions in the send-currency.js file that build on the base module to add new behavior for sending issued currency between accounts.
### Create Trust Line
A trust line enables two accounts to trade a defined currency up to a set limit. This gives the participants assurance that any exchanges are between known entities at agreed upon maximum amounts.
+Connect to the XRPL server.
+
```javascript
-// *******************************************************
-// ***************** Create TrustLine ********************
-// *******************************************************
-
-async function createTrustline() {
- let net = getNet()
+async function createTrustLine() {
+ const net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
-
await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
-```
-
-Get the standby and operational wallets.
-
-```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
-```
-
-Capture the currency code from the standby currency field.
-
-```javascript
- const currency_code = standbyCurrencyField.value
+ let results = "\nConnected. Creating trust line.\n"
+ resultField.value = results
```
-Define the transaction, capturing the currency code and (limit) amount from the form fields.
+Create a `TrustSet` transaction, passing the currency code, issuer account, and the total value the holder is willing to accept.
```javascript
- const trustSet_tx = {
- "TransactionType": "TrustSet",
- "Account": standbyDestinationField.value,
- "LimitAmount": {
- "currency": standbyCurrencyField.value,
- "issuer": standby_wallet.address,
- "value": standbyAmountField.value
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const trustSet_tx = {
+ "TransactionType": "TrustSet",
+ "Account": accountAddressField.value,
+ "LimitAmount": {
+ "currency": currencyField.value,
+ "issuer": issuerField.value,
+ "value": amountField.value
+ }
}
- }
```
-Prepare the transaction by automatically filling the default parameters.
-
-```javascript
- const ts_prepared = await client.autofill(trustSet_tx)
-```
-
-
-Sign the transaction.
-
+Autofill the remaining default transaction parameters.
```javascript
- const ts_signed = operational_wallet.sign(ts_prepared)
- results += '\nCreating trust line from operational account to standby account...'
- standbyResultField.value = results
+ const ts_prepared = await client.autofill(trustSet_tx)
```
-
-Submit the transaction and wait for the results.
-
+Sign and send the transaction to the XRPL server, then wait for the results.
```javascript
+ const ts_signed = wallet.sign(ts_prepared)
+ resultField.value = results
const ts_result = await client.submitAndWait(ts_signed.tx_blob)
```
-
-Report the results.
-
+Report the results of the transaction.
```javascript
- if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += '\nTrustline established between account \n' +
- standbyDestinationField.value + ' \n and account\n' + standby_wallet.address + '.'
- standbyResultField.value = results
- } else {
- results += '\nTrustLine failed. See JavaScript console for details.'
- document.getElementById('standbyResultField').value = results
- throw 'Error sending transaction: ${ts_result.result.meta.TransactionResult}'
+ if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
+ results += '\n===Trust line established between account \n' +
+ accountAddressField.value + ' \n and account\n' + issuerField.value + '.'
+ resultField.value = results
+ } else {
+ results += `\n===Transaction failed: ${ts_result.result.meta.TransactionResult}`
+ resultField.value = results
+ }
}
-} //End of createTrustline()
-
-```
-
-### Send Issued Currency
-
-Once you have created a trust line from an account to your own, you can send issued currency tokens to that account, up to the established limit.
-
-```javascript
-// *******************************************************
-// *************** Send Issued Currency ******************
-// *******************************************************
-
-async function sendCurrency() {
```
-Connect to the ledger.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
-
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- document.getElementById('standbyResultField').value = results
-
- await client.connect()
-
- results += '\nConnected.'
- standbyResultField.value = results
-```
-
-Get the account wallets.
-
-```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const currency_code = standbyCurrencyField.value
- const issue_quantity = standbyAmountField.value
-
- const send_token_tx = {
- "TransactionType": "Payment",
- "Account": standby_wallet.address,
- "Amount": {
- "currency": standbyCurrencyField.value,
- "value": standbyAmountField.value,
- "issuer": standby_wallet.address
- },
- "Destination": standbyDestinationField.value
+ catch (error) {
+ console.error('===Error creating trust line:', error);
+ results += `\n===Error: ${error.message}\n`
+ resultField.value = results
+ throw error; // Re-throw the error to be handled by the caller
}
-```
-
-
-Prepare the transaction by automatically filling default values.
-
-
-```javascript
- const pay_prepared = await client.autofill(send_token_tx)
-```
-
-
-Sign the transaction.
-
-
-```javascript
- const pay_signed = standby_wallet.sign(pay_prepared)
- results += 'Sending ${issue_quantity} ${currency_code} to ' +
- standbyDestinationField.value + '...'
- standbyResultField.value = results
-```
-
-
-Submit the transaction and wait for the results.
-
-
-```javascript
- const pay_result = await client.submitAndWait(pay_signed.tx_blob)
-```
-
-
-Report the results.
-
-
-```javascript
- if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}'
- standbyResultField.value = results
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- standbyResultField.value = results
- throw 'Error sending transaction: ${pay_result.result.meta.TransactionResult}'
+ finally {
+ // Disconnect from the client
+ await client.disconnect();
}
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- getBalances()
- client.disconnect()
-} // end of sendCurrency()
+}
+//End of createTrustline()
```
+### sendCurrency()
+This transaction actually sends a transaction that changes balances on both sides of the trust line.
-
-### Get Balances
-
-
-```javascript
-// *******************************************************
-// ****************** Get Balances ***********************
-// *******************************************************
-
-async function getBalances() {
-```
-
-Connect to the ledger.
+Connect to the XRP Ledger and get the account wallet.
```javascript
+async function sendCurrency() {
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
- await client.connect()
+ resultField.value = results
+ await client.connect()
results += '\nConnected.'
- standbyResultField.value = results
-```
-
-Get the account wallets.
-
-```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- results = "\nGetting standby account balances...\n"
-```
-
-Define and send the request for the standby account, then wait for the results.
-
-```javascript
- const standby_balances = await client.request({
- command: "gateway_balances",
- account: standby_wallet.address,
- ledger_index: "validated",
- hotwallet: [operational_wallet.address]
- })
-```
-
-Report the results.
-
-```javascript
- results += JSON.stringify(standby_balances.result, null, 2)
- standbyResultField.value = results
-```
-
-Define and send the request for the operational account, then wait for the results.
-
-```javascript
- results += "\nGetting operational account balances...\n"
- const operational_balances = await client.request({
- command: "gateway_balances",
- account: operational_wallet.address,
- ledger_index: "validated"
- })
+ resultField.value = results
```
-Report the results.
+Create a payment transaction to the destination account, specifying the amount using the currency, value, and issuer.
```javascript
- results += JSON.stringify(operational_balances.result, null, 2)
- operationalResultField.value = results
-```
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const send_currency_tx = {
+ "TransactionType": "Payment",
+ "Account": wallet.address,
+ "Amount": {
+ "currency": currencyField.value,
+ "value": amountField.value,
+ "issuer": issuerField.value
+ },
+ "Destination": destinationField.value
+ }
+ ```
-Update the form with current XRP balances.
+Autofill the remaining default transaction parameters.
```javascript
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- standbyResultField.value = results
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
+ const pay_prepared = await client.autofill(send_currency_tx)
```
-Disconnect from the ledger.
+Sign and send the prepared payment transaction to the XRP Ledger, then await and report the results.
```javascript
- client.disconnect()
-} // End of getBalances()
+ const pay_signed = wallet.sign(pay_prepared)
+ results += `\n\n===Sending ${amountField.value} ${currencyField.value} to ${destinationField.value} ...`
+ resultField.value = results
+ const pay_result = await client.submitAndWait(pay_signed.tx_blob)
+ if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
+ results += '\n===Transaction succeeded.'
+ resultField.value = results
+ } else {
+ results += `\n===Transaction failed: ${pay_result.result.meta.TransactionResult}`
+ resultField.value = results
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
+ }
+ }
```
-### Reciprocal Transactions
-
-For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary. The `getBalances()` request does not have a reciprocal transaction, because it reports balances for both accounts.
+Update the XRP value field to reflect the transaction fee.
```javascript
-// *******************************************************
-// ************ Create Operational TrustLine *************
-// *******************************************************
-
-async function oPcreateTrustline() {
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
-
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const trustSet_tx = {
- "TransactionType": "TrustSet",
- "Account": operationalDestinationField.value,
- "LimitAmount": {
- "currency": operationalCurrencyField.value,
- "issuer": operational_wallet.address,
- "value": operationalAmountField.value
- }
- }
- const ts_prepared = await client.autofill(trustSet_tx)
- const ts_signed = standby_wallet.sign(ts_prepared)
- results += '\nCreating trust line from operational account to ' +
- operationalDestinationField.value + ' account...'
- operationalResultField.value = results
- const ts_result = await client.submitAndWait(ts_signed.tx_blob)
- if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += '\nTrustline established between account \n' + operational_wallet.address +
- ' \n and account\n' + operationalDestinationField.value + '.'
- operationalResultField.value = results
- } else {
- results += '\nTrustLine failed. See JavaScript console for details.'
- operationalResultField.value = results
- throw 'Error sending transaction: ${ts_result.result.meta.TransactionResult}'
- }
-} //End of oPcreateTrustline
-
-// *******************************************************
-// ************* Operational Send Issued Currency ********
-// *******************************************************
-
-async function oPsendCurrency() {
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
-
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
- const currency_code = operationalCurrencyField.value
- const issue_quantity = operationalAmountField.value
-
- const send_token_tx = {
- "TransactionType": "Payment",
- "Account": operational_wallet.address,
- "Amount": {
- "currency": currency_code,
- "value": issue_quantity,
- "issuer": operational_wallet.address
- },
- "Destination": operationalDestinationField.value
+ catch (error) {
+ console.error('Error sending transaction:', error);
+ results += `\nError: ${error.message}\n`
+ resultField.value = results
+ throw error; // Re-throw the error to be handled by the caller
}
-
- const pay_prepared = await client.autofill(send_token_tx)
- const pay_signed = operational_wallet.sign(pay_prepared)
- results += 'Sending ${issue_quantity} ${currency_code} to ' +
- operationalDestinationField.value + '...'
- operationalResultField.value = results
- const pay_result = await client.submitAndWait(pay_signed.tx_blob)
- if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}'
- operationalResultField.value = results
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- operationalResultField.value = results
- throw 'Error sending transaction: ${pay_result.result.meta.TransactionResult}'
+ finally {
+ // Disconnect from the client
+ await client.disconnect();
}
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- getBalances()
- client.disconnect()
-} // end of oPsendCurrency()
+} // end of sendCurrency()
+
```
-## 2.create-trustline-send-currency.html
+## send-currency.html
Update the form to support the new functions.
```html
-
- Token Test Harness
+
+ Send Currency
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
Token Test Harness
+
+
Send Currency
-
+
+
```
diff --git a/docs/tutorials/javascript/send-payments/index.md b/docs/tutorials/javascript/send-payments/index.md
index 417d57b7408..9d8a791ba7c 100644
--- a/docs/tutorials/javascript/send-payments/index.md
+++ b/docs/tutorials/javascript/send-payments/index.md
@@ -1,7 +1,12 @@
---
-html: send-payments-using-javascript.html
-parent: javascript.html
top_nav_grouping: Article Types
+seo:
+ description: Send XRP and Issued Currencies on the XRPL.
+labels:
+ - Accounts
+ - Transactions
+ - XRP
+ - Issued Currencies
metadata:
indexPage: true
---
@@ -9,5 +14,7 @@ metadata:
Send XRP and issued currency on the XRP Ledger using JavaScript.
+Download and expand the [Payment Modular Tutorial Samples](/_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
+
{% child-pages /%}
diff --git a/docs/tutorials/javascript/send-payments/send-and-cash-checks.md b/docs/tutorials/javascript/send-payments/send-and-cash-checks.md
index 245527b3545..803b66f0e5e 100644
--- a/docs/tutorials/javascript/send-payments/send-and-cash-checks.md
+++ b/docs/tutorials/javascript/send-payments/send-and-cash-checks.md
@@ -1,9 +1,7 @@
---
-html: send-and-cash-checks.html
-parent: send-payments-using-javascript.html
labels:
- Accounts
- - Quickstart
+ - Modular Tutorials
- Transaction Sending
- Checks
- XRP
@@ -23,11 +21,11 @@ Checks offer another option for transferring funds between accounts. Checks have
2. The receiver can choose to accept less than the full amount of the check. This allows you to authorize a maximum amount when the actual cost is not finalized.
-[](/docs/img/quickstart-checks1.png)
+[](/docs/img/mt-send-checks-1-empty-form.png)
## Prerequisites
-Clone or download the {% repo-link path="_code-samples/quickstart/js/" %}Modular Tutorial Samples{% /repo-link %}.
+Download and expand the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
{% admonition type="info" name="Note" %}
Without the Modular Tutorial Samples, you will not be able to try the examples that follow.
@@ -37,47 +35,51 @@ Without the Modular Tutorial Samples, you will not be able to try the examples t
To get test accounts:
-1. Open and launch `10check.html`.
-2. Click **Get Standby Account**.
-3. Click **Get Operational Account**.
+1. Open `send-checks.html` in a browser.
+2. Get test accounts.
+ 1. If you copied the gathered information from another tutorial:
+ 1. Paste the gathered information to the **Result** field.
+ 2. Click **Distribute Account Info**.
+ 2. If you have an existing account seed:
+ 1. Paste the account seed to the **Account 1 Seed** or **Account 2 Seed** field.
+ 2. Click **Get Account 1 from Seed** or **Get Account 2 from Seed**.
+ 2. If you do not have existing accounts:
+ 1. Click **Get New Account 1**.
+ 2. Click **Get New Account 2**.
-[](/docs/img/quickstart-checks2.png)
-
-You can transfer XRP between your new accounts. Each account has its own fields and buttons.
-
-
-
-
+[](/docs/img/mt-send-checks-2-form-with-accounts.png)
### Send a Check for XRP
-To send a check for XRP from the Standby account to the Operational account:
+To send a check for XRP:
-1. On the Standby (left) side of the form, enter the **Amount** of XRP to send, in drops.
-2. Copy and paste the **Operational Account** field to the Standby **Destination** field.
-3. Set the **Currency** to _XRP_.
+1. Select **Account 1** or **Account 2**.
+2. Enter the **Amount** of XRP to send, in drops.
+2. Enter the receiving account address in the **Destination** field.
+3. Set the **Currency Code** to _XRP_.
4. Click **Send Check**.
-[](/docs/img/quickstart-checks3.png)
+[](/docs/img/mt-send-checks-3-send-xrp.png)
### Send a Check for an Issued Currency
-To send a check for an issued currency token from the Standby account to the Operational account:
+To send a check for an issued currency token:
-1. On the Standby side of the form, enter the **Amount** of currency to send.
-2. Copy and paste the **Operational Account** field to the Standby **Destination** field.
-3. Copy the **Standby Account** field and paste the value in the **Issuer** field.
-4. Enter the **Currency** code for your token.
-5. Click **Send Check**.
+1. Choose **Account 1** or **Account 2**.
+2. Enter the **Amount** of currency to send.
+3. Enter the receiving account address in the **Destination** field.
+4. Enter the issuing account in the **Issuer** field (for example, the account sending the check).
+5. Enter the **Currency** code for your issued currency token.
+6. Click **Send Check**.
-[](/docs/img/quickstart-checks4.png)
+[](/docs/img/mt-send-checks-4-send-currency.png)
### Get Checks
Click **Get Checks** to get a list of the current checks you have sent or received. To uniquely identify a check (for example, when cashing a check), use the check's ledger entry ID, in the `index` field.
-[](/docs/img/quickstart-checks5.png)
+[](/docs/img/mt-send-checks-5-get-checks.png)
### Cash Check
@@ -86,20 +88,19 @@ To cash a check you have received:
1. Enter the **Check ID** (**index** value).
2. Enter the **Amount** you want to collect, up to the full amount of the check.
3. Enter the currency code.
- a. If you cashing a check for XRP, enter _XRP_ in the **Currency** field.
- b. If you are cashing a check for an issued currency token:
+ a. If you are cashing a check for XRP, enter _XRP_ in the **Currency Code** field.
+ b. If you are cashing a check for an issued currency token:
1. Enter the **Issuer** of the token.
- 2. Enter the **Currency** code for the token.
+ 2. Enter the **Currency Code** code for the token.
4. Click **Cash Check**.
-[](/docs/img/quickstart-checks6.png)
-
+[](/docs/img/mt-send-checks-6-cash-check.png)
-### Get Balances
+### Get Token Balance
-Click **Get Balances** to get a list of obligations and assets for each account.
+Click **Get Token Balance** to get a list of obligations and assets for the account.
-[](/docs/img/quickstart-checks7.png)
+[](/docs/img/mt-send-checks-7-get-balance.png)
### Cancel Check
@@ -108,14 +109,13 @@ To cancel a check you have previously sent to another account.
1. Enter the **Check ID** (`index` value).
2. Click **Cancel Check**.
-[](/docs/img/quickstart-checks8.png)
-
+[](/docs/img/mt-send-checks-8-cancel-check.png)
# Code Walkthrough
-You can download the {% repo-link path="_code-samples/quickstart/js/" %}Modular Tutorial Samples{% /repo-link %} in the source repository for this website.
+Download and expand the [Modular Tutorials](../../../../_code-samples/modular-tutorials/payment-modular-tutorials.zip) archive.
-## ripplex10-check.js
+## send-checks.js
### sendCheck()
@@ -125,779 +125,539 @@ Connect to the XRP ledger.
async function sendCheck() {
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
+ results = `\n===Connected to ${net}.===\n===Sending check.===\n`
+ resultField.value = results
```
-Instantiate the account wallets.
+Prepare the transaction. Set the *check_amount* variable to the value in the **Amount** field.
```javascript
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ let check_amount = amountField.value
```
-Create the `check_amount` variable, based on the standby amount field.
+ If the currency field is not _XRP_, create an `amount` object with the _currency_, _value_, and _issuer_. Otherwise, use the *check_amount* value as is.
-```javascript
- var check_amount = standbyAmountField.value
-```
+ ```javascript
+ if (currencyField.value != "XRP") {
+ check_amount = {
+ "currency": currencyField.value,
+ "value": amountField.value,
+ "issuer": wallet.address
+ }
+ }
+ ```
-If the currency is anything but _XRP_, it's an issued currency. Update the `check_amount` variable to include the `currency` and `issuer` fields.
+ Create the transaction object.
-```javascript
- if (standbyCurrencyField.value != "XRP") {
- check_amount = {
- "currency": standbyCurrencyField.value,
- "value": standbyAmountField.value,
- "issuer": standby_wallet.address
- }
- }
-```
-
-Define the `CheckCreate` transaction.
-
-```javascript
+ ```javascript
const send_check_tx = {
"TransactionType": "CheckCreate",
- "Account": standby_wallet.address,
+ "Account": wallet.address,
"SendMax": check_amount,
- "Destination": standbyDestinationField.value
+ "Destination": destinationField.value
}
```
-Prepare and sign the transaction.
+Autofill the remaining values and sign the prepared transaction.
```javascript
- const check_prepared = await client.autofill(send_check_tx)
- const check_signed = standby_wallet.sign(check_prepared)
- results += 'Sending ' + check_amount + ' ' + standbyCurrencyField + ' to ' +
- standbyDestinationField.value + '...'
- standbyResultField.value = results
-```
-
-Submit the transaction to the XRP Ledger and wait for the response.
-
-```
- const check_result = await client.submitAndWait(check_signed.tx_blob)
+ const check_prepared = await client.autofill(send_check_tx)
+ const check_signed = wallet.sign(check_prepared)
```
-Report the results
+Send the transaction and wait for the results.
```javascript
- if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${check_signed.hash}'
- standbyResultField.value = JSON.stringify(check_result.result, null, 2)
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- standbyResultField.value = results
- throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
- }
+ results += '\n===Sending ' + amountField.value + ' ' + currencyField.
+ value + ' to ' + destinationField.value + '.===\n'
+ resultField.value = results
+ const check_result = await client.submitAndWait(check_signed.tx_blob)
```
-Update the XRP balance fields.
+Report the results.
```javascript
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
+ if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
+ results = '===Transaction succeeded===\n\n'
+ resultField.value += results + JSON.stringify(check_result.result, null, 2)
+ }
```
-Disconnect from the XRP Ledger.
+Update the **XRP Balance** field.
```javascript
- client.disconnect()
-} // end of sendCheck()
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
```
-### getChecks()
+Report any errors, then disconnect from the XRP ledger.
```javascript
-async function getChecks() {
+ } catch (error) {
+ results = `Error sending transaction: ${error}`
+ resultField.value += results
+ }
+ finally {
+ client.disconnect()
+ }
+}//end of sendCheck()
```
-Connect to the XRP Ledger.
+## getChecks()
+Connect to the XRP Ledger.
```javascript
+async function getChecks() {
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
- results= "\nGetting standby account checks...\n"
+ let results = `\n===Connected to ${net}.===\n===Getting account checks.===\n\n`
+ resultField.value = results
```
-Define and send the `account_objects` request, specifying `check` objects.
+Define an `account_objects` query, filtering for the _check_ object type.
```javascript
- const check_objects = await client.request({
- "id": 5,
- "command": "account_objects",
- "account": standbyAccountField.value,
- "ledger_index": "validated",
- "type": "check"
- })
+ try {
+ const check_objects = await client.request({
+ "id": 5,
+ "command": "account_objects",
+ "account": accountAddressField.value,
+ "ledger_index": "validated",
+ "type": "check"
+ })
```
-
-Report the results.
+Display the retrieved `Check` objects in the result field.
```javascript
- standbyResultField.value = JSON.stringify(check_objects.result, null, 2)
+ resultField.value += JSON.stringify(check_objects.result, null, 2)
```
-Disconnect from the XRP Ledger.
+Catch and report any errors, then disconnect from the XRP Ledger.
```javascript
- client.disconnect()
+ } catch (error) {
+ results = `Error getting checks: ${error}`
+ resultField.value += results
+ }
+ finally {
+ client.disconnect()
+ }
} // End of getChecks()
```
-### cashCheck()
-Connect to the XRP Ledger and instantiate the account wallets.
+## cashCheck()
+
+Connect to the XRP Ledger and get the account wallet
```javascript
async function cashCheck() {
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
+ results = `\n===Connected to ${net}.===\n===Cashing check.===\n`
+ resultField.value = results
```
-Set the `check_amount` variable to the value in the **Amount** field.
+Set the check amount.
```javascript
- var check_amount = standbyAmountField.value
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ let check_amount = amountField.value
```
-If the **Currency** is anything other than `XRP`, the check is for an issued currency. Redefine the variable to include the `currency` and `issuer` for the token.
+If the currency is not _XRP_, create an `amount` object with _value_, _currency_, and _issuer_.
+```javascript
+ if (currencyField.value != "XRP") {
+ check_amount = {
+ "value": amountField.value,
+ "currency": currencyField.value,
+ "issuer": issuerField.value
+ }
+ }
```
- if (standbyCurrencyField.value != "XRP") {
- check_amount = {
- "value": standbyAmountField.value,
- "currency": standbyCurrencyField.value,
- "issuer": standbyIssuerField.value
- }
- }
+
+Create the `CheckCash` transaction object.
+
+```javascript
+ const cash_check_tx = {
+ "TransactionType": "CheckCash",
+ "Account": wallet.address,
+ "Amount": check_amount,
+ "CheckID": checkIdField.value
+ }
```
-Define the `CheckCash` transaction.
+Autofill the transaction details.
```javascript
- const cash_check_tx = {
- "TransactionType": "CheckCash",
- "Account": standby_wallet.address,
- "Amount": check_amount,
- "CheckID": standbyCheckID.value
- }
+ const cash_prepared = await client.autofill(cash_check_tx)
```
-Prepare and sign the transaction.
+Sign the prepared transaction.
```javascript
- const cash_prepared = await client.autofill(cash_check_tx)
- const cash_signed = standby_wallet.sign(cash_prepared)
- results += ' Receiving ' + standbyAmountField.value + ' ' + standbyCurrencyField.value + '.\n'
- standbyResultField.value = results
+ const cash_signed = wallet.sign(cash_prepared)
+ results = ' Receiving ' + amountField.value + ' ' + currencyField.value + '.\n'
+ resultField.value += results
```
-Submit the transaction and wait for the results.
+Submit the transaction and wait for the result.
```javascript
const check_result = await client.submitAndWait(cash_signed.tx_blob)
-```
+ ```
-Report the results.
+Report the transaction results.
```javascript
- if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
- standbyResultField.value = results
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- standbyResultField.value = results
- throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
- }
+ if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
+ results = '===Transaction succeeded===\n' + JSON.stringify(check_result.result, null, 2)
+ resultField.value += results
+ }
```
-Update the XRP balance fields.
+Update the XRP Balance field.
```javascript
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address));
```
-Disconnect from the XRP Ledger.
+Catch and report any errors, then disconnect from the XRP ledger.
```javascript
- client.disconnect()
+ } catch (error) {
+ results = `Error sending transaction: ${error}`
+ resultField.value += results
+ }
+ finally {
+ client.disconnect()
} // end of cashCheck()
```
-### cancelCheck
+## cancelCheck()
-Connect to the XRP Ledger and instantiate the account wallets.
+Connect to the XRP Ledger.
```javascript
async function cancelCheck() {
let net = getNet()
const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- standbyResultField.value = results
await client.connect()
- results += '\nConnected.'
- standbyResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
+ results = `\n===Connected to ${net}.===\n===Cancelling check.===\n`
+ resultField.value = results
```
-Define the `CheckCancel` transaction.
+Create the CheckCancel transaction object, passing the wallet address and the Check ID value (the _Index_).
```javascript
- const cancel_check_tx = {
- "TransactionType": "CheckCancel",
- "Account": standby_wallet.address,
- "CheckID": standbyCheckID.value
- }
+ try {
+ const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
+ const cancel_check_tx = {
+ "TransactionType": "CheckCancel",
+ "Account": wallet.address,
+ "CheckID": checkIdField.value
+ }
```
-Prepare and sign the transaction object.
+Autofill the transaction details.
```javascript
- const cancel_prepared = await client.autofill(cancel_check_tx)
- const cancel_signed = standby_wallet.sign(cancel_prepared)
- results += ' Cancelling check.\n'
- standbyResultField.value = results
+ const cancel_prepared = await client.autofill(cancel_check_tx)
```
-Submit the transaction and wait for the results.
+Sign the prepared transaction.
```javascript
- const check_result = await client.submitAndWait(cancel_signed.tx_blob)
+ const cancel_signed = wallet.sign(cancel_prepared)
```
-Report the results.
+Submit the transaction and wait for the results.
```javascript
- if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
- standbyResultField.value = results
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- standbyResultField.value = results
- throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
- }
+ const check_result = await client.submitAndWait(cancel_signed.tx_blob)
```
-Update the XRP balance fields.
+Report the transaction results.
```javascript
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
+ if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
+ results += `===Transaction succeeded===\n${check_result.result.meta.TransactionResult}`
+ resultField.value = results
+ }
```
-Disconnect from the XRP Ledger.
+Update the XRP Balance field.
```javascript
- client.disconnect()
-} // end of cancelCheck()
+ xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
```
-### Reciprocal functions for the Operational account.
+Catch and report any errors, then disconnect from the XRP ledger.
```javascript
-// *******************************************************
-// ************ Operational Send Check *******************
-// *******************************************************
-async function opSendCheck() {
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
-
- const issue_quantity = operationalAmountField.value
- var check_amount = operationalAmountField.value
-
- if (operationalCurrencyField.value != "XRP") {
- check_amount = {
- "currency": operationalCurrencyField.value,
- "value": operationalAmountField.value,
- "issuer": operational_wallet.address
- }
- }
- const send_check_tx = {
- "TransactionType": "CheckCreate",
- "Account": operational_wallet.address,
- "SendMax": check_amount,
- "Destination": operationalDestinationField.value
- }
- const check_prepared = await client.autofill(send_check_tx)
- const check_signed = operational_wallet.sign(check_prepared)
- results += '\nSending check to ' +
- operationalDestinationField.value + '...'
- operationalResultField.value = results
- const check_result = await client.submitAndWait(check_signed.tx_blob)
- if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${check_signed.hash}'
- operationalResultField.value = JSON.stringify(check_result.result, null, 2)
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- operationalResultField.value = results
- throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
- }
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- client.disconnect()
-} // end of opSendCheck()
-
-// *******************************************************
-// ************ Operational Get Checks *******************
-// *******************************************************
-
-async function opGetChecks() {
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- results= "\nGetting standby account checks...\n"
- const check_objects = await client.request({
- "id": 5,
- "command": "account_objects",
- "account": operationalAccountField.value,
- "ledger_index": "validated",
- "type": "check"
- })
- operationalResultField.value = JSON.stringify(check_objects.result, null, 2)
- client.disconnect()
-} // End of opGetChecks()
-
-
-// *******************************************************
-// ************* Operational Cash Check ******************
-// *******************************************************
-
-async function opCashCheck() {
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
-
- var check_amount = operationalAmountField.value
-
- if (operationalCurrencyField.value != "XRP") {
- check_amount = {
- "value": operationalAmountField.value,
- "currency": operationalCurrencyField.value,
- "issuer": operationalIssuerField.value
- }
- }
- const cash_check_tx = {
- "TransactionType": "CheckCash",
- "Account": operational_wallet.address,
- "Amount": check_amount,
- "CheckID": operationalCheckIDField.value
- }
- const cash_prepared = await client.autofill(cash_check_tx)
- const cash_signed = operational_wallet.sign(cash_prepared)
- results += ' Receiving ' + operationalAmountField.value + ' ' + operationalCurrencyField.value + '.\n'
- operationalResultField.value = results
- const check_result = await client.submitAndWait(cash_signed.tx_blob)
- if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
- operationalResultField.value = results
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- operationalResultField.value = results
- throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
+ } catch (error) {
+ results = `Error sending transaction: ${error}`
+ resultField.value += results
}
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- client.disconnect()
-}
-// end of opCashCheck()
-
-// *******************************************************
-// ************* Operational Cancel Check ****************
-// *******************************************************
-
-async function opCancelCheck() {
- let net = getNet()
- const client = new xrpl.Client(net)
- results = 'Connecting to ' + getNet() + '....'
- operationalResultField.value = results
- await client.connect()
- results += '\nConnected.'
- operationalResultField.value = results
-
- const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
- const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
-
- const cancel_check_tx = {
- "TransactionType": "CheckCancel",
- "Account": operational_wallet.address,
- "CheckID": operationalCheckIDField.value
+ finally {
+ client.disconnect()
}
-
- const cancel_prepared = await client.autofill(cancel_check_tx)
- const cancel_signed = operational_wallet.sign(cancel_prepared)
- results += ' Cancelling check.\n'
- operationalResultField.value = results
- const check_result = await client.submitAndWait(cancel_signed.tx_blob)
- if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
- results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
- operationalResultField.value = results
- } else {
- results += 'Transaction failed: See JavaScript console for details.'
- operationalResultField.value = results
- throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
- }
- standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
- operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
- client.disconnect()
} // end of cancelCheck()
```
-## 10.check.html
+## 10.send-checks.html
```html
-
- Token Test Harness
+
+ Send Checks
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
Token Test Harness
+
+
Send Checks
-
+
+
```
diff --git a/docs/tutorials/javascript/send-payments/sending-mpts.md b/docs/tutorials/javascript/send-payments/sending-mpts.md
index 52cfa2c32bb..e4e9679c22e 100644
--- a/docs/tutorials/javascript/send-payments/sending-mpts.md
+++ b/docs/tutorials/javascript/send-payments/sending-mpts.md
@@ -17,7 +17,7 @@ Once an account receives an MPT, it can send the MPT to another account, provide
The Send MPT utility lets you create an account, authorize it to receive a specific MPT issuance, then send it the authorized MPT from an issuer or holder account. (You can issue an MPT using the [MPT Generator](../../../use-cases/tokenization/creating-an-asset-backed-multi-purpose-token.md) utility.)
-
+[](../../../img/mt-send-mpt-0-empty-form.png)
You can download a [standalone version of the MPT Sender](../../../../_code-samples/mpt-sender/send-mpt.zip) as sample code.
@@ -31,13 +31,13 @@ To get the accounts:
2. Choose your ledger instance (**Devnet** or **Testnet**).
3. If you used the MPT Generator:
1. Paste the gathered info in the **Result** field.
- 
+ [](../../../img/mt-send-mpt-1-gathered-info.png)
2. Cut and paste the MPT Issuance ID to the **MPT Issuance ID** field.
3. Click **Distribute Account Info** to populate the **Account 1** fields.