+
+Code Sample - Issue a Token
+
+
+
+
+
+Open your browser's console (F12) to see the logs.
+
diff --git a/content/_code-samples/issue-a-token/issue-a-token.js b/content/_code-samples/issue-a-token/issue-a-token.js
index 6e712808fa..ceae5a0fcf 100644
--- a/content/_code-samples/issue-a-token/issue-a-token.js
+++ b/content/_code-samples/issue-a-token/issue-a-token.js
@@ -1,12 +1,7 @@
-// Example credentials
-let hot_address = "rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH"
-let hot_secret = "sn3nxiW7v8KXzPzAqzyHXbSSKNuN9"
-let cold_address = ""
-let cold_secret = ""
-
// Connect ---------------------------------------------------------------------
// ripple = require('ripple-lib') // For Node.js. In browsers, use
-
+
Open your browser's console (F12) to see the logs.
diff --git a/content/_code-samples/rippleapi_quickstart/semi-reliable-submit.js b/content/_code-samples/rippleapi_quickstart/semi-reliable-submit.js
deleted file mode 100644
index 3a80a13ff9..0000000000
--- a/content/_code-samples/rippleapi_quickstart/semi-reliable-submit.js
+++ /dev/null
@@ -1,85 +0,0 @@
-function lookup_tx_final(tx_id, max_ledger, min_ledger) {
- if (typeof min_ledger == "undefined") {
- min_ledger = -1
- }
- if (typeof max_ledger == "undefined") {
- max_ledger = -1
- }
- if (min_ledger > max_ledger) {
- // Assume the args were just passed backwards & swap them
- [min_ledger, max_ledger] = [max_ledger, min_ledger]
- }
-
- // Helper to determine if we (should) know the transaction's final result yet.
- // If the server has validated all ledgers the tx could possibly appear in,
- // then we should know its final result.
- async function server_has_ledger_range(min_ledger, max_ledger) {
- const si = await api.request("server_info")
- if (si.info.complete_ledgers == "empty") {
- console.warn("Connected server is not synced.")
- return false
- }
- // In case of a discontiguous set, use only the last set, since we need
- // continuous history from submission to expiration to know that a
- // transaction failed to achieve consensus.
- const ledger_ranges = si.info.complete_ledgers.split(',')
- // Note: last_range can be in the form 'x-y' or just 'y'
- const last_range = ledger_ranges[ledger_ranges.length -1].split('-')
- const lr_min = parseInt(last_range[0])
- const lr_max = parseInt(last_range[last_range.length - 1])
- const max_validated = Math.min(lr_max, lr_max)
- if (lr_min <= min_ledger && max_validated >= max_ledger) {
- return true
- }
- return false
- }
-
- return new Promise((resolve, reject) => {
- api.on('ledger', async (ledger) => {
- try {
- tx_result = await api.request("tx", {
- "transaction": tx_id,
- "min_ledger": min_ledger,
- "max_ledger": max_ledger
- })
-
- if (tx_result.validated) {
- resolve(tx_result.meta.TransactionResult)
- } else if (max_ledger > ledger.ledgerVersion) {
- // Transaction found, not validated, but we should have a final result
- // by now.
- // Work around https://github.com/ripple/rippled/issues/3727
- if (server_has_ledger_range(min_ledger, max_ledger)) {
- // Transaction should have been validated by now.
- reject(`Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this ledger is correct.`)
- } else {
- reject("Can't get final result. Check a full history server.")
- }
- } else {
- // Transaction may still be validated later. Keep waiting.
- }
- } catch(e) {
- if (e.data.error == "txnNotFound") {
- if (e.data.searched_all) {
- reject(`Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`)
- } else {
- if (max_ledger > ledger.ledgerVersion) {
- // Transaction may yet be confirmed. This would not be a bad time
- // to resubmit the transaction just in case.
- } else {
- // Work around https://github.com/ripple/rippled/issues/3750
- if (server_has_ledger_range(min_ledger, max_ledger)) {
- reject(`Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`)
- } else {
- reject("Can't get final result. Check a full history server.")
- }
- }
- }
- } else {
- // Unknown error; pass it back up
- reject(`Unknown Error: ${e}`)
- }
- }
- }) // end ledger event handler
- }) // end promise def
-}
diff --git a/content/_code-samples/rippleapi_quickstart/submit-and-verify.js b/content/_code-samples/rippleapi_quickstart/submit-and-verify.js
deleted file mode 100644
index b243bfee97..0000000000
--- a/content/_code-samples/rippleapi_quickstart/submit-and-verify.js
+++ /dev/null
@@ -1,90 +0,0 @@
-'use strict';
-/* import RippleAPI and support libraries */
-const RippleAPI = require('ripple-lib').RippleAPI;
-
-/* Credentials of the account placing the order */
-const myAddr = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn';
-const mySecret = 's████████████████████████████';
-
-/* Define the order to place here */
-const myOrder = {
- 'direction': 'buy',
- 'quantity': {
- 'currency': 'FOO',
- 'counterparty': 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v',
- 'value': '100'
- },
- 'totalPrice': {
- 'currency': 'XRP',
- 'value': '1000'
- }
-};
-
-/* Milliseconds to wait between checks for a new ledger. */
-const INTERVAL = 1000;
-/* Instantiate RippleAPI. Uses s2 (full history server) */
-const api = new RippleAPI({server: 'wss://s2.ripple.com'});
-/* Number of ledgers to check for valid transaction before failing */
-const ledgerOffset = 5;
-const myInstructions = {maxLedgerVersionOffset: ledgerOffset};
-
-
-/* Verify a transaction is in a validated XRP Ledger version */
-function verifyTransaction(hash, options) {
- console.log('Verifying Transaction');
- return api.getTransaction(hash, options).then(data => {
- console.log('Final Result: ', data.outcome.result);
- console.log('Validated in Ledger: ', data.outcome.ledgerVersion);
- console.log('Sequence: ', data.sequence);
- return data.outcome.result === 'tesSUCCESS';
- }).catch(error => {
- /* If transaction not in latest validated ledger,
- try again until max ledger hit */
- if (error instanceof api.errors.PendingLedgerVersionError) {
- return new Promise((resolve, reject) => {
- setTimeout(() => verifyTransaction(hash, options)
- .then(resolve, reject), INTERVAL);
- });
- }
- return error;
- });
-}
-
-
-/* Function to prepare, sign, and submit a transaction to the XRP Ledger. */
-function submitTransaction(lastClosedLedgerVersion, prepared, secret) {
- const signedData = api.sign(prepared.txJSON, secret);
- return api.submit(signedData.signedTransaction).then(data => {
- console.log('Tentative Result: ', data.resultCode);
- console.log('Tentative Message: ', data.resultMessage);
- /* The tentative result should be ignored. Transactions that succeed here can ultimately fail,
- and transactions that fail here can ultimately succeed. */
-
- /* Begin validation workflow */
- const options = {
- minLedgerVersion: lastClosedLedgerVersion,
- maxLedgerVersion: prepared.instructions.maxLedgerVersion
- };
- return new Promise((resolve, reject) => {
- setTimeout(() => verifyTransaction(signedData.id, options)
- .then(resolve, reject), INTERVAL);
- });
- });
-}
-
-
-api.connect().then(() => {
- console.log('Connected');
- return api.prepareOrder(myAddr, myOrder, myInstructions);
-}).then(prepared => {
- console.log('Order Prepared');
- return api.getLedger().then(ledger => {
- console.log('Current Ledger', ledger.ledgerVersion);
- return submitTransaction(ledger.ledgerVersion, prepared, mySecret);
- });
-}).then(() => {
- api.disconnect().then(() => {
- console.log('api disconnected');
- process.exit();
- });
-}).catch(console.error);
diff --git a/content/_code-samples/send-xrp/demo.html b/content/_code-samples/send-xrp/demo.html
index f2cef38026..c397d71002 100644
--- a/content/_code-samples/send-xrp/demo.html
+++ b/content/_code-samples/send-xrp/demo.html
@@ -5,7 +5,7 @@
Code Sample - Send XRP
-
+
Open your browser's console (F12) to see the logs.
diff --git a/content/_code-samples/submit-and-verify/README.md b/content/_code-samples/submit-and-verify/README.md
new file mode 100644
index 0000000000..ccbb5440e3
--- /dev/null
+++ b/content/_code-samples/submit-and-verify/README.md
@@ -0,0 +1,32 @@
+# Submit and Verify
+
+Example JavaScript code using ripple-lib to submit a signed transaction blob and wait until it has a final result.
+
+Example usage:
+
+```js
+// example testnet creds. Don't use for real
+const address = "raXDGCShEGqYz2d94qkv1UmAh2uJd3UTea"
+const secret = "ssNBEKCkEY3W6YFfrjcSoNit91Vvj"
+api = new ripple.RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
+api.connect()
+api.on('connected', async () => {
+ const prepared = await api.prepareTransaction({
+ "TransactionType": "AccountSet",
+ "Account": address
+ })
+ const signed = api.sign(prepared.txJSON, secret)
+
+ const result = await submit_and_verify(api, signed.signedTransaction)
+
+ if (result == "tesSUCCESS") {
+ console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${signed.id}`)
+ } else if (result == "unknown") {
+ console.log(`Transaction status unknown. `)
+ } else if (result == "tefMAX_LEDGER") {
+ console.log(`Transaction failed to achieve a consensus.`)
+ } else {
+ console.log(`Transaction failed with code ${result}: https://testnet.xrpl.org/transactions/${signed.id}`)
+ }
+}
+```
diff --git a/content/_code-samples/submit-and-verify/submit-and-verify.js b/content/_code-samples/submit-and-verify/submit-and-verify.js
new file mode 100644
index 0000000000..668455c16a
--- /dev/null
+++ b/content/_code-samples/submit-and-verify/submit-and-verify.js
@@ -0,0 +1,167 @@
+// Submit-and-verify XRPL transaction using ripple-lib (v1.x)
+// Demonstrates how to submit a transaction and wait for validation.
+// This is not true "robust" transaction submission because it does not protect
+// against power outages or other sudden interruptions.
+
+// Look up a transaction's result.
+// Arguments:
+// @param api object RippleAPI instance connected to the network where you
+// submitted the transaction.
+// @param tx_id string The identifying hash of the transaction.
+// @param max_ledger int optional The highest ledger index where the
+// transaction can be validated.
+// @param min_ledger int optional The lowest ledger index where the
+// transaction can be validated.
+// Returns: Promise