diff --git a/assets/js/interactive-tutorial.js b/assets/js/interactive-tutorial.js
index 1122b0b7ab..1a33e85f71 100644
--- a/assets/js/interactive-tutorial.js
+++ b/assets/js/interactive-tutorial.js
@@ -520,12 +520,12 @@ async function generic_full_send(event, tx_json, wallet) {
`
${tl("Prepared transaction:")}
${pretty_print(prepared)} `)
- const signed = wallet.signTransaction(prepared)
+ const {tx_blob, hash} = wallet.sign(prepared)
block.find(".output-area").append(
- `${tl("Transaction hash:")} ${xrpl.computeSignedTransactionHash(signed)}
`)
+ `${tl("Transaction hash:")} ${hash}
`)
// TODO: update computeSignedTransactionHash if that changes
- await do_submit(block, {"tx_blob": signed}, wait_step_name)
+ await do_submit(block, {"tx_blob": tx_blob}, wait_step_name)
}
/**
diff --git a/assets/js/submit-and-verify2.js b/assets/js/submit-and-verify2.js
deleted file mode 100644
index 2db20c8bb7..0000000000
--- a/assets/js/submit-and-verify2.js
+++ /dev/null
@@ -1,183 +0,0 @@
-// Submit-and-verify XRPL transaction using xrpl.js (v2.0)
-// 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 Client instance connected to the network where you
-// submitted the transaction. MUST ALREADY BE SUBSCRIBED TO THE
-// `ledger` event stream.
-// @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 -> result of the tx command with the transaction's
-// validated transaction results.
-// On failure, the reason is an object with two fields:
-// - failure_final: if true, this transaction did not achieve consensus and
-// it can never be validated in the future (assuming the
-// min_ledger and max_ledger values provided were accurate).
-// - msg: A human-readable message explaining what happened.
-function lookup_tx_final(api, 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]
- }
-
- // Make sure we're subscribed to the ledger stream to trigger updates
- api.request({"command": "subscribe", "streams": ["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({command: "server_info"})
- // console.log(`Server has ledger range: ${si.result.info.complete_ledgers}`)
- if (si.result.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.result.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])
- if (lr_min <= min_ledger && lr_max >= max_ledger) {
- // Server has ledger range needed.
- return true
- }
- return false
- }
-
- return new Promise((resolve, reject) => {
- ledger_listener = async (ledger) => {
- try {
- const tx_response = await api.request({
- "command": "tx",
- "transaction": tx_id,
- "min_ledger": min_ledger,
- "max_ledger": max_ledger
- })
-
- if (tx_response.result.validated) {
- resolve(tx_response.result.meta.TransactionResult)
- } else if (ledger.ledger_index >= max_ledger) {
- api.off("ledgerClosed", ledger_listener)
- // Transaction found, not validated, but we should have a final result
- // by now.
- // Work around https://github.com/ripple/rippled/issues/3727
- if (await server_has_ledger_range(min_ledger, max_ledger)) {
- // Transaction should have been validated by now.
- reject({
- failure_final: true,
- msg: `Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`
- })
- } else {
- reject({
- failure_final: false,
- msg: "Can't get final result (1). Check a full history server."
- })
- }
- } else {
- // Transaction may still be validated later. Keep waiting.
- }
- } catch(e) {
- console.warn(e)
- if (e.data.error == "txnNotFound") {
- if (e.data.searched_all) {
- api.off("ledgerClosed", ledger_listener)
- reject({
- failure_final: true,
- msg: `Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`
- })
- } else {
- if (max_ledger > ledger.ledger_index) {
- api.off("ledgerClosed", ledger_listener)
- // 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 (await server_has_ledger_range(min_ledger, max_ledger)) {
- reject({
- failure_final: true,
- msg: `Transaction not found in ledgers ${min_ledger}-${max_ledger}. This result is final if this range is correct.`
- })
- } else {
- reject({
- failure_final: false,
- msg: "Can't get final result. Check a full history server."
- })
- }
- }
- }
- } else {
- // Unknown error; pass it back up
- reject({
- failure_final: false,
- msg: `Unknown Error: ${e}`
- })
- }
- }
- } // end ledger event handler
- api.on('ledgerClosed', ledger_listener)
- }) // end promise def
-}
-
-
-// Submit a transaction blob and get its final result as a string.
-// This can be one of these possibilities:
-// tesSUCCESS. The transaction executed successfully.
-// tec*. The transaction was validated with a failure code. It destroyed the XRP
-// transaction cost and may have done some cleanup such as removing
-// expired objects from the ledger, but nothing else.
-// See https://xrpl.org/tec-codes.html for the full list.
-// tefMAX_LEDGER. The transaction expired without ever being included
-// in a validated ledger.
-// unknown. Either the server you are querying does not have the
-// necessary ledger history to find the transaction's final result, or
-// something else went wrong when trying to look up the results. The
-// warning written to the console can tell you more about what happened.
-async function submit_and_verify(api, tx_blob) {
- // Make sure we subscribe to the ledger stream. This is idempotent so we don't
- // have to worry about oversubscribing.
- api.request({"command": "subscribe", "streams": ["ledger"]})
- const prelim = await api.request({"command": "submit", "tx_blob": tx_blob})
- console.log("Preliminary result code:", prelim.result.engine_result)
- const min_ledger = prelim.result.validated_ledger_index
- if (prelim.result.tx_json.LastLedgerSequence === undefined) {
- console.warn("Transaction has no LastLedgerSequence field. "+
- "It may be impossible to determine final failure.")
- }
- const max_ledger = prelim.result.tx_json.LastLedgerSequence
- const tx_id = prelim.result.tx_json.hash
-
- let final_result
- try {
- final_result = await lookup_tx_final(api, tx_id, max_ledger, min_ledger)
- } catch(reason) {
- if (reason.failure_final) final_result = "tefMAX_LEDGER"
- else final_result = "unknown"
- console.warn(reason)
- }
-
- return final_result;
-}
-
-// Exports for node.js; no-op for browsers
-if (typeof module !== "undefined") {
- module.exports = {
- submit_and_verify: submit_and_verify,
- lookup_tx_final: lookup_tx_final
- }
-}
diff --git a/assets/js/tutorials/issue-a-token.js b/assets/js/tutorials/issue-a-token.js
index 29b627fe33..f972aad96a 100644
--- a/assets/js/tutorials/issue-a-token.js
+++ b/assets/js/tutorials/issue-a-token.js
@@ -128,10 +128,10 @@ $(document).ready(() => {
let flags = 0
if ($("#cold-require-dest").prop("checked")) {
- flags |= xrpl.AccountSetTransactionFlags.tfRequireDestTag
+ flags |= xrpl.AccountSetTfFlags.tfRequireDestTag
}
if ($("#cold-disallow-xrp").prop("checked")) {
- flags |= xrpl.AccountSetTransactionFlags.tfDisallowXRP
+ flags |= xrpl.AccountSetTfFlags.tfDisallowXRP
}
const tick_size = parseInt($("#cold-tick-size").val(), 10)
@@ -153,10 +153,10 @@ $(document).ready(() => {
try {
const cold_settings_tx = {
"TransactionType": "AccountSet",
- "Account": cold_wallet.classicAddress,
+ "Account": cold_wallet.address,
"TransferRate": transfer_rate,
"TickSize": tick_size,
- "SetFlag": xrpl.AccountSetFlags.asfDefaultRipple,
+ "SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple,
"Domain": domain,
"Flags": flags
}
@@ -179,10 +179,10 @@ $(document).ready(() => {
let flags = 0
if ($("#hot-require-dest").prop("checked")) {
- flags |= xrpl.AccountSetTransactionFlags.tfRequireDestTag
+ flags |= xrpl.AccountSetTfFlags.tfRequireDestTag
}
if ($("#hot-disallow-xrp").prop("checked")) {
- flags |= xrpl.AccountSetTransactionFlags.tfDisallowXRP
+ flags |= xrpl.AccountSetTfFlags.tfDisallowXRP
}
const domain = $("#hot-domain-hex").text().trim()
@@ -191,9 +191,9 @@ $(document).ready(() => {
try {
const hot_settings_tx = {
"TransactionType": "AccountSet",
- "Account": hot_wallet.classicAddress,
+ "Account": hot_wallet.address,
// Require Auth so we can't accidentally issue from the hot address
- "SetFlag": xrpl.AccountSetFlags.asfRequireAuth,
+ "SetFlag": xrpl.AccountSetAsfFlags.asfRequireAuth,
"Domain": domain,
"Flags": flags
}
@@ -211,7 +211,7 @@ $(document).ready(() => {
$("#create-trust-line-button").click( async (event) => {
const block = $(event.target).closest(".interactive-block")
block.find(".output-area").empty()
- const cold_address = get_wallet_2(event, "cold").classicAddress
+ const cold_address = get_wallet_2(event, "cold").address
const hot_wallet = get_wallet_2(event, "hot")
let currency_code
@@ -234,7 +234,7 @@ $(document).ready(() => {
try {
const trust_set_tx = {
"TransactionType": "TrustSet",
- "Account": hot_wallet.classicAddress,
+ "Account": hot_wallet.address,
"LimitAmount": {
"currency": currency_code,
"issuer": cold_address,
@@ -254,7 +254,7 @@ $(document).ready(() => {
$("#send-token-button").click( async (event) => {
const block = $(event.target).closest(".interactive-block")
block.find(".output-area").empty()
- const hot_address = get_wallet_2(event, "hot").classicAddress
+ const hot_address = get_wallet_2(event, "hot").address
const cold_wallet = get_wallet_2(event, "cold")
const currency_code = $("#send-currency-code").text().trim()
@@ -274,11 +274,11 @@ $(document).ready(() => {
try {
const send_token_tx = {
"TransactionType": "Payment",
- "Account": cold_wallet.classicAddress,
+ "Account": cold_wallet.address,
"Amount": {
"currency": currency_code,
"value": issue_quantity,
- "issuer": cold_wallet.classicAddress
+ "issuer": cold_wallet.address
},
"Destination": hot_address
}
@@ -299,8 +299,8 @@ $(document).ready(() => {
$("#confirm-balances-button").click( async (event) => {
const block = $(event.target).closest(".interactive-block")
block.find(".output-area").empty()
- const hot_address = get_wallet_2(event, "hot").classicAddress
- const cold_address = get_wallet_2(event, "cold").classicAddress
+ const hot_address = get_wallet_2(event, "hot").address
+ const cold_address = get_wallet_2(event, "cold").address
block.find(".loader").show()
try {
diff --git a/assets/js/tutorials/require-destination-tags.js b/assets/js/tutorials/require-destination-tags.js
index 6095dcd8da..7fe39e3b5f 100644
--- a/assets/js/tutorials/require-destination-tags.js
+++ b/assets/js/tutorials/require-destination-tags.js
@@ -66,7 +66,7 @@ $(document).ready(() => {
let seed = block.data("testSendSecret")
if (!seed) {
console.debug("First-time setup for test sender...")
- test_sender_wallet = await api.generateFaucetWallet()
+ test_sender_wallet = (await api.fundWallet()).wallet
block.data("testSendSecret", test_sender_wallet.seed)
// First time: Wait for our test sender to be fully funded, so we don't
@@ -75,7 +75,7 @@ $(document).ready(() => {
try {
await api.request({
"command": "account_info",
- "account": test_sender_wallet.classicAddress,
+ "account": test_sender_wallet.address,
"ledger_index": "validated"
})
break
@@ -101,7 +101,7 @@ $(document).ready(() => {
const test_sender = await get_test_sender(block)
const tx_json = {
"TransactionType": "Payment",
- "Account": test_sender.classicAddress,
+ "Account": test_sender.address,
"Amount": "3152021",
"Destination": address
}
@@ -111,15 +111,14 @@ $(document).ready(() => {
}
const prepared = await api.autofill(tx_json)
- const tx_blob = test_sender.signTransaction(prepared)
+ const {tx_blob, hash} = test_sender.sign(prepared)
console.debug("Submitting test payment", prepared)
const prelim = await api.request({"command": "submit", tx_blob})
- const tx_hash = xrpl.computeSignedTransactionHash(tx_blob)
block.find(".loader").hide()
block.find(".output-area").append(`${tx_json.TransactionType}
${prepared.Sequence} ${(dt?"WITH":"WITHOUT")} Dest. Tag:
- ${prelim.result.engine_result}
`)
} catch(err) {
block.find(".loader").hide()
diff --git a/assets/js/tutorials/send-xrp.js b/assets/js/tutorials/send-xrp.js
index fc59bd882b..1ef4e68ad3 100644
--- a/assets/js/tutorials/send-xrp.js
+++ b/assets/js/tutorials/send-xrp.js
@@ -44,13 +44,12 @@ $("#sign-button").click( function(event) {
const wallet = get_wallet(event)
if (!wallet) {return}
- signed = wallet.signTransaction(preparedTxJSON)
- hash = xrpl.computeSignedTransactionHash(signed) // TODO: update if computeSignedTransactionHash changes
+ {tx_blob, hash} = wallet.sign(preparedTxJSON)
block.find(".output-area").html(
`Signed Transaction blob:
${signed}
+ >${tx_blob}
Identifying hash: ${hash}
`
)
diff --git a/assets/js/tutorials/use-tickets.js b/assets/js/tutorials/use-tickets.js
index 79eb1bf0cf..268b81fc0d 100644
--- a/assets/js/tutorials/use-tickets.js
+++ b/assets/js/tutorials/use-tickets.js
@@ -49,9 +49,9 @@ $("#prepare-and-sign").click( async function(event) {
}
const vli = await api.getLedgerIndex()
- let prepared = await api.autofill({
+ const prepared = await api.autofill({
"TransactionType": "TicketCreate",
- "Account": wallet.classicAddress,
+ "Account": wallet.address,
"TicketCount": 10,
"Sequence": current_sequence,
"LastLedgerSequence": vli+LLS_OFFSET
@@ -61,10 +61,9 @@ $("#prepare-and-sign").click( async function(event) {
`Prepared transaction:
${pretty_print(prepared)} `)
- let tx_blob = wallet.signTransaction(prepared)
- let tx_id = xrpl.computeSignedTransactionHash(tx_blob)
+ const {tx_blob, hash} = wallet.sign(prepared)
block.find(".output-area").append(
- `Transaction hash: ${tx_id}
`)
+ `Transaction hash: ${hash}
`)
block.find(".output-area").append(
`Signed blob:
${tx_blob} `)
@@ -84,16 +83,15 @@ async function intermission_submit(event, tx_json) {
const wallet = get_wallet(event)
if (!wallet) {return}
const prepared = await api.autofill(tx_json)
- const tx_blob = wallet.signTransaction(prepared)
+ const {tx_blob, hash} = wallet.sign(prepared)
const prelim = await api.request({
"command": "submit",
"tx_blob": tx_blob
})
- const tx_id = xrpl.computeSignedTransactionHash(tx_blob)
block.find(".output-area").append(`${prepared.TransactionType}
${prepared.Sequence}:
- ${prelim.result.engine_result}
`)
}
@@ -187,7 +185,7 @@ $("#prepare-ticketed-tx").click(async function(event) {
const prepared_t = await api.autofill({
"TransactionType": "AccountSet",
- "Account": wallet.classicAddress,
+ "Account": wallet.address,
"TicketSequence": use_ticket,
"Sequence": 0,
"LastLedgerSequence": vli+LLS_OFFSET
@@ -197,14 +195,13 @@ $("#prepare-ticketed-tx").click(async function(event) {
`Prepared transaction:
${pretty_print(prepared_t)} `)
- const tx_blob_t = wallet.signTransaction(prepared_t)
- const tx_id_t = xrpl.computeSignedTransactionHash(tx_blob_t)
+ const {tx_blob, hash} = wallet.sign(prepared_t)
block.find(".output-area").append(
- `Transaction hash: ${tx_id_t}
`)
+ `Transaction hash: ${hash}
`)
block.find(".output-area").append(
`
- ${tx_blob_t} `)
+ ${tx_blob}`)
// Update breadcrumbs & activate next step
complete_step("Prepare Ticketed Tx")
diff --git a/assets/js/tx-sender.js b/assets/js/tx-sender.js
index 364cac0d2a..1c5cfed278 100644
--- a/assets/js/tx-sender.js
+++ b/assets/js/tx-sender.js
@@ -47,7 +47,7 @@ const set_up_tx_sender = async function() {
api = new xrpl.Client(TESTNET_URL)
let sending_wallet
- let xrp_balance
+ let xrp_balance = "TBD"
function enable_buttons_if_ready() {
if ( (typeof sending_wallet) === "undefined") {
@@ -72,17 +72,18 @@ const set_up_tx_sender = async function() {
console.debug("Getting a sending address from the faucet...")
try {
- sending_wallet = await api.generateFaucetWallet()
+ const fund_response = await api.fundWallet()
+ sending_wallet = fund_response.wallet
+ xrp_balance = xrpl.dropsToXrp(fund_response.balance)
} catch(error) {
console.error(error)
errorNotif("There was an error with the XRP Ledger Testnet Faucet. Reload this page to try again.")
return
}
- xrp_balance = "TBD" // TODO old faucet command gave balance, new doesn't
$("#balance-item").text(xrp_balance)
- $(".sending-address-item").text(sending_wallet.classicAddress)
+ $(".sending-address-item").text(sending_wallet.address)
$("#init_button").prop("disabled", "disabled")
$("#init_button").addClass("disabled")
$("#init_button").attr("title", "Done")
@@ -112,10 +113,11 @@ const set_up_tx_sender = async function() {
}
async function update_xrp_balance() {
- balances = await api.getBalances(sending_wallet.classicAddress, {currency: "XRP"})
+ balances = await api.getBalances(sending_wallet.address, {currency: "XRP"})
$("#balance-item").text(balances[0].value)
}
+
async function submit_and_notify(tx_object, use_wallet, silent) {
if (use_wallet === undefined) {
use_wallet = sending_wallet
@@ -132,31 +134,9 @@ const set_up_tx_sender = async function() {
return
}
- // Determine first and last ledger the tx could be validated in *BEFORE*
- // signing it.
- min_ledger = await api.getLedgerIndex()
- max_ledger = prepared.LastLedgerSequence
-
-
- let signed
try {
- // Sign, submit
- signed = use_wallet.signTransaction(prepared)
- await api.request({"command": "submit", "tx_blob": signed})
- } catch (error) {
- console.log(error)
- if (!silent) {
- errorNotif(`Error signing & submitting ${tx_object.TransactionType} tx: ${error}`)
- }
- return
- }
-
- // Wait for tx to be in a validated ledger or to expire
- const hash = xrpl.computeSignedTransactionHash(signed)
-
- try {
- // use lookup_tx_final() from submit-and-verify2.js
- let final_result_data = await lookup_tx_final(api, hash, max_ledger, min_ledger)
+ const {tx_blob, hash} = use_wallet.sign(prepared)
+ const final_result_data = await api.submitSignedReliable(tx_blob)
console.log("final_result_data is", final_result_data)
let final_result = final_result_data.result.meta.TransactionResult
if (!silent) {
@@ -169,12 +149,13 @@ const set_up_tx_sender = async function() {
logTx(tx_object.TransactionType, hash, final_result)
}
update_xrp_balance()
- return data
- } catch(error) {
+ return final_result_data
+ } catch (error) {
console.log(error)
if (!silent) {
- errorNotif("Error submitting "+tx_object.TransactionType+" tx: "+error)
+ errorNotif(`Error signing & submitting ${tx_object.TransactionType} tx: ${error}`)
}
+ return
}
}
@@ -196,32 +177,19 @@ const set_up_tx_sender = async function() {
$("#pp_progress .progress-bar").addClass("progress-bar-animated")
// 1. Get a funded address to use as issuer
try {
- pp_issuer_wallet = await api.generateFaucetWallet()
+ const fund_response = await api.fundWallet()
+ pp_issuer_wallet = fund_response.wallet
} catch(error) {
console.log("Error getting issuer address for partial payments:", error)
return
}
$("#pp_progress .progress-bar").width("20%")
- // Wait for the address's funding to be validated so we don't get the wrong
- // starting sequence number.
- while (true) {
- try {
- await new Promise(resolve => setTimeout(resolve, 1000))
- await api.request({
- command: "account_info",
- account: pp_issuer_wallet.classicAddress,
- ledger_index: "validated"
- })
- break
- } catch(e) {}
- }
-
// 2. Set Default Ripple on issuer
let resp = await submit_and_notify({
TransactionType: "AccountSet",
- Account: pp_issuer_wallet.classicAddress,
- SetFlag: 8
+ Account: pp_issuer_wallet.address,
+ SetFlag: xrpl.AccountSetAsfFlags.asfDefaultRipple
}, pp_issuer_wallet, true)
if (resp === undefined) {
console.log("Couldn't set Default Ripple for partial payment issuer")
@@ -232,11 +200,11 @@ const set_up_tx_sender = async function() {
// 3. Make a trust line from sending address to issuer
resp = await submit_and_notify({
TransactionType: "TrustSet",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
LimitAmount: {
currency: pp_sending_currency,
value: "1000000000", // arbitrarily, 1 billion fake currency
- issuer: pp_issuer_wallet.classicAddress
+ issuer: pp_issuer_wallet.address
}
}, sending_wallet, true)
if (resp === undefined) {
@@ -248,12 +216,12 @@ const set_up_tx_sender = async function() {
// 4. Issue fake currency to main sending address
resp = await submit_and_notify({
TransactionType: "Payment",
- Account: pp_issuer_wallet.classicAddress,
- Destination: sending_wallet.classicAddress,
+ Account: pp_issuer_wallet.address,
+ Destination: sending_wallet.address,
Amount: {
currency: pp_sending_currency,
value: "1000000000",
- issuer: pp_issuer_wallet.classicAddress
+ issuer: pp_issuer_wallet.address
}
}, pp_issuer_wallet, true)
if (resp === undefined) {
@@ -267,12 +235,12 @@ const set_up_tx_sender = async function() {
// so they end up paying themselves issued currency then delivering XRP.
resp = await submit_and_notify({
TransactionType: "OfferCreate",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
TakerGets: "1000000000000000", // 1 billion XRP
TakerPays: {
currency: pp_sending_currency,
value: "1000000000",
- issuer: pp_issuer_wallet.classicAddress
+ issuer: pp_issuer_wallet.address
}
}, sending_wallet, true)
if (resp === undefined) {
@@ -295,7 +263,7 @@ const set_up_tx_sender = async function() {
// Destination Address box -----------------------------------------------
async function on_dest_address_update(event) {
const d_a = $("#destination_address").val()
- if (api.isValidClassicAddress(d_a) || api.isValidXAddress(d_a)) { // TODO: switch back to isValidAddress
+ if (xrpl.isValidAddress(d_a)) {
$("#destination_address").addClass("is-valid").removeClass("is-invalid")
if (d_a[0] == "X") {
$("#x-address-warning").show()
@@ -323,7 +291,7 @@ const set_up_tx_sender = async function() {
$("#send_xrp_payment button").prop("disabled","disabled")
await submit_and_notify({
TransactionType: "Payment",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
Destination: destination_address,
Amount: xrp_drops_input
})
@@ -341,17 +309,16 @@ const set_up_tx_sender = async function() {
await submit_and_notify({
TransactionType: "Payment",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
Destination: destination_address,
Amount: "1000000000000000", // 1 billion XRP
SendMax: {
value: (Math.random()*.01).toPrecision(15), // random very small amount
currency: pp_sending_currency,
- issuer: pp_issuer_wallet.classicAddress
+ issuer: pp_issuer_wallet.address
},
- Flags: api.txFlags.Payment.PartialPayment | api.txFlags.Universal.FullyCanonicalSig
+ Flags: xrpl.PaymentFlags.tfPartialPayment
})
- // TODO: follow txFlags wherever they get moved to
$("#send_partial_payment .loader").hide()
$("#send_partial_payment button").prop("disabled",false)
}
@@ -375,13 +342,13 @@ const set_up_tx_sender = async function() {
$("#create_escrow button").prop("disabled","disabled")
const escrowcreate_tx_data = await submit_and_notify({
TransactionType: "EscrowCreate",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
Destination: destination_address,
Amount: "1000000",
FinishAfter: finish_after
})
- if (release_auto) {
+ if (escrowcreate_tx_data && release_auto) {
// Wait until there's a ledger with a close time > FinishAfter
// to submit the EscrowFinish
$("#escrow_progress .progress-bar").width("0%").addClass("progress-bar-animated")
@@ -414,10 +381,10 @@ const set_up_tx_sender = async function() {
// Future feature: submit from a different sender, just to prove that
// escrows can be finished by a third party
await submit_and_notify({
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
TransactionType: "EscrowFinish",
- Owner: sending_wallet.classicAddress,
- OfferSequence: escrowcreate_tx_data.sequence
+ Owner: sending_wallet.address,
+ OfferSequence: escrowcreate_tx_data.result.Sequence
})
}
$("#create_escrow .loader").hide()
@@ -434,7 +401,7 @@ const set_up_tx_sender = async function() {
$("#create_payment_channel button").prop("disabled","disabled")
await submit_and_notify({
TransactionType: "PaymentChannelCreate",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
Destination: destination_address,
Amount: xrp_drops_input,
SettleDelay: 30,
@@ -459,12 +426,12 @@ const set_up_tx_sender = async function() {
// Future feature: cross-currency sending with paths?
await submit_and_notify({
TransactionType: "Payment",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
Destination: destination_address,
Amount: {
"currency": issue_code,
"value": issue_amount,
- "issuer": sending_wallet.classicAddress
+ "issuer": sending_wallet.address
}
})
$("#send_issued_currency .loader").hide()
@@ -481,7 +448,7 @@ const set_up_tx_sender = async function() {
$("#trust_for button").prop("disabled","disabled")
await submit_and_notify({
TransactionType: "TrustSet",
- Account: sending_wallet.classicAddress,
+ Account: sending_wallet.address,
LimitAmount: {
currency: trust_currency_code,
value: trust_limit,
diff --git a/content/_code-samples/issue-a-token/js/issue-a-token.js b/content/_code-samples/issue-a-token/js/issue-a-token.js
index 56671d5c98..600e199d46 100644
--- a/content/_code-samples/issue-a-token/js/issue-a-token.js
+++ b/content/_code-samples/issue-a-token/js/issue-a-token.js
@@ -6,7 +6,6 @@
if (typeof module !== "undefined") {
// gotta use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
- var submit_and_verify = require('../../submit-and-verify/submit-and-verify2.js').submit_and_verify
} else {
// TODO: remove when webpack is fixed
var xrpl = ripple;
@@ -20,55 +19,28 @@ async function main() {
// Get credentials from the Testnet Faucet -----------------------------------
console.log("Requesting addresses from the Testnet faucet...")
- const hot_wallet = await api.generateFaucetWallet()
- const cold_wallet = await api.generateFaucetWallet()
-
- console.log("Waiting until we have a validated starting sequence number...")
- // If you go too soon, the funding transaction might slip back a ledger and
- // then your starting Sequence number will be off. This is mostly relevant
- // when you want to use a Testnet account right after getting a reply from
- // the faucet.
- while (true) {
- try {
- await api.request({
- command: "account_info",
- account: cold_wallet.classicAddress,
- ledger_index: "validated"
- })
- await api.request({
- command: "account_info",
- account: hot_wallet.classicAddress,
- ledger_index: "validated"
- })
- break
- } catch(e) {
- if (e.data.error != 'actNotFound') throw e
- await new Promise(resolve => setTimeout(resolve, 1000))
- }
- }
- console.log(`Got hot address ${hot_wallet.classicAddress} and cold address ${cold_wallet.classicAddress}.`)
+ const hot_wallet = (await api.fundWallet()).wallet
+ const cold_wallet = (await api.fundWallet()).wallet
+ console.log(`Got hot address ${hot_wallet.address} and cold address ${cold_wallet.address}.`)
// Configure issuer (cold address) settings ----------------------------------
const cold_settings_tx = {
"TransactionType": "AccountSet",
- "Account": cold_wallet.classicAddress,
+ "Account": cold_wallet.address,
"TransferRate": 0,
"TickSize": 5,
"Domain": "6578616D706C652E636F6D", // "example.com"
- "SetFlag": 8 // enable Default Ripple
- //"Flags": (api.txFlags.AccountSet.DisallowXRP |
- // api.txFlags.AccountSet.RequireDestTag)
- // TODO: update to txFlags' new location?
+ "SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
+ //"Flags": (xrpl.AccountSetTfFlags.tfDisallowXRP |
+ // xrpl.AccountSetTfFlags.tfRequireDestTag)
}
const cst_prepared = await api.autofill(cold_settings_tx)
- const cst_signed = cold_wallet.signTransaction(cst_prepared)
- // submit_and_verify helper function from:
- // https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/submit-and-verify/
+ const cst_signed = cold_wallet.sign(cst_prepared)
console.log("Sending cold address AccountSet transaction...")
- const cst_result = await submit_and_verify(api, cst_signed)
- if (cst_result == "tesSUCCESS") {
- console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${xrpl.computeSignedTransactionHash(cst_signed)}`)
+ const cst_result = await api.submitSignedReliable(cst_signed.tx_blob)
+ if (cst_result.result.meta.TransactionResult == "tesSUCCESS") {
+ console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${cst_signed.hash}`)
} else {
throw `Error sending transaction: ${cst_result}`
}
@@ -78,7 +50,7 @@ async function main() {
const hot_settings_tx = {
"TransactionType": "AccountSet",
- "Account": hot_wallet.classicAddress,
+ "Account": hot_wallet.address,
"Domain": "6578616D706C652E636F6D", // "example.com"
"SetFlag": 2 // enable Require Auth so we can't use trust lines that users
// make to the hot address, even by accident.
@@ -87,13 +59,13 @@ async function main() {
}
const hst_prepared = await api.autofill(hot_settings_tx)
- const hst_signed = hot_wallet.signTransaction(hst_prepared)
+ const hst_signed = hot_wallet.sign(hst_prepared)
console.log("Sending hot address AccountSet transaction...")
- const hst_result = await submit_and_verify(api, hst_signed)
- if (hst_result == "tesSUCCESS") {
- console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${xrpl.computeSignedTransactionHash(hst_signed)}`)
+ const hst_result = await api.submitSignedReliable(hst_signed.tx_blob)
+ if (hst_result.result.meta.TransactionResult == "tesSUCCESS") {
+ console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${hst_signed.hash}`)
} else {
- throw `Error sending transaction: ${hst_result}`
+ throw `Error sending transaction: ${hst_result.result.meta.TransactionResult}`
}
@@ -101,22 +73,22 @@ async function main() {
const currency_code = "FOO"
const trust_set_tx = {
"TransactionType": "TrustSet",
- "Account": hot_wallet.classicAddress,
+ "Account": hot_wallet.address,
"LimitAmount": {
"currency": currency_code,
- "issuer": cold_wallet.classicAddress,
+ "issuer": cold_wallet.address,
"value": "10000000000" // Large limit, arbitrarily chosen
}
}
const ts_prepared = await api.autofill(trust_set_tx)
- const ts_signed = hot_wallet.signTransaction(ts_prepared)
+ const ts_signed = hot_wallet.sign(ts_prepared)
console.log("Creating trust line from hot address to issuer...")
- const ts_result = await submit_and_verify(api, ts_signed)
- if (ts_result == "tesSUCCESS") {
- console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${xrpl.computeSignedTransactionHash(ts_signed)}`)
+ const ts_result = await api.submitSignedReliable(ts_signed.tx_blob)
+ if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
+ console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${ts_signed.hash}`)
} else {
- throw `Error sending transaction: ${ts_result}`
+ throw `Error sending transaction: ${ts_result.result.meta.TransactionResult}`
}
@@ -124,31 +96,30 @@ async function main() {
const issue_quantity = "3840"
const send_token_tx = {
"TransactionType": "Payment",
- "Account": cold_wallet.classicAddress,
+ "Account": cold_wallet.address,
"Amount": {
"currency": currency_code,
"value": issue_quantity,
- "issuer": cold_wallet.classicAddress
+ "issuer": cold_wallet.address
},
- "Destination": hot_wallet.classicAddress
+ "Destination": hot_wallet.address
}
const pay_prepared = await api.autofill(send_token_tx)
- const pay_signed = cold_wallet.signTransaction(pay_prepared)
- // submit_and_verify helper from _code-samples/submit-and-verify
- console.log(`Sending ${issue_quantity} ${currency_code} to ${hot_wallet.classicAddress}...`)
- const pay_result = await submit_and_verify(api, pay_signed)
- if (pay_result == "tesSUCCESS") {
- console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${xrpl.computeSignedTransactionHash(pay_signed)}`)
+ const pay_signed = cold_wallet.sign(pay_prepared)
+ console.log(`Sending ${issue_quantity} ${currency_code} to ${hot_wallet.address}...`)
+ const pay_result = await api.submitSignedReliable(pay_signed.tx_blob)
+ if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
+ console.log(`Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}`)
} else {
- throw `Error sending transaction: ${pay_result}`
+ throw `Error sending transaction: ${pay_result.result.meta.TransactionResult}`
}
// Check balances ------------------------------------------------------------
console.log("Getting hot address balances...")
const hot_balances = await api.request({
command: "account_lines",
- account: hot_wallet.classicAddress,
+ account: hot_wallet.address,
ledger_index: "validated"
})
console.log(hot_balances.result)
@@ -156,9 +127,9 @@ async function main() {
console.log("Getting cold address balances...")
const cold_balances = await api.request({
command: "gateway_balances",
- account: cold_wallet.classicAddress,
+ account: cold_wallet.address,
ledger_index: "validated",
- hotwallet: [hot_wallet.classicAddress]
+ hotwallet: [hot_wallet.address]
})
console.log(JSON.stringify(cold_balances.result, null, 2))
diff --git a/content/_code-samples/secure-signing/js/signPayment.js b/content/_code-samples/secure-signing/js/signPayment.js
index a37fb3a54a..f4c9e5acd2 100644
--- a/content/_code-samples/secure-signing/js/signPayment.js
+++ b/content/_code-samples/secure-signing/js/signPayment.js
@@ -9,7 +9,7 @@ let my_seq = 21404872
// Provide *all* required fields before signing a transaction
const txJSON = {
- "Account": my_wallet.classicAddress,
+ "Account": my_wallet.address,
"TransactionType":"Payment",
"Destination":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"Amount":"13000000",
@@ -19,7 +19,7 @@ const txJSON = {
"Sequence": my_seq
}
-const tx_blob = my_wallet.signTransaction(txJSON)
+const signed = my_wallet.sign(txJSON)
-console.log("tx_blob is:", tx_blob)
-console.log("tx hash is:", xrpl.computeBinaryTransactionSigningHash(tx_blob))
+console.log("tx_blob is:", signed.tx_blob)
+console.log("tx hash is:", signed.hash)
diff --git a/content/_code-samples/send-xrp/send-xrp.js b/content/_code-samples/send-xrp/send-xrp.js
index 6bbed85c63..baa8b4f225 100644
--- a/content/_code-samples/send-xrp/send-xrp.js
+++ b/content/_code-samples/send-xrp/send-xrp.js
@@ -8,30 +8,13 @@ api.connect()
api.on('connected', async () => {
// Get credentials from the Testnet Faucet -----------------------------------
- const wallet = await api.generateFaucetWallet()
-
- console.log("Waiting until we have a validated starting sequence number...")
- // If you go too soon, the funding transaction might slip back a ledger and
- // then your starting Sequence number will be off. This is mostly relevant
- // when you want to use a Testnet account right after getting a reply from
- // the faucet.
- while (true) {
- try {
- await api.request({
- command: "account_info",
- account: wallet.classicAddress,
- ledger_index: "validated"
- })
- break
- } catch(e) {
- await new Promise(resolve => setTimeout(resolve, 1000))
- }
- }
+ console.log("Getting a wallet from the Testnet faucet...")
+ const {wallet, balance} = await api.fundWallet()
// Prepare transaction -------------------------------------------------------
const prepared = await api.autofill({
"TransactionType": "Payment",
- "Account": wallet.classicAddress,
+ "Account": wallet.address,
"Amount": xrpl.xrpToDrops("22"),
"Destination": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
})
@@ -41,10 +24,9 @@ api.on('connected', async () => {
console.log("Transaction expires after ledger:", max_ledger)
// Sign prepared instructions ------------------------------------------------
- const tx_blob = wallet.signTransaction(prepared)
- const txID = xrpl.computeSignedTransactionHash(tx_blob)
- console.log("Identifying hash:", txID)
- console.log("Signed blob:", tx_blob)
+ const signed = wallet.sign(prepared)
+ console.log("Identifying hash:", signed.hash)
+ console.log("Signed blob:", signed.tx_blob)
// Submit signed blob --------------------------------------------------------
// The earliest ledger a transaction could appear in is the first ledger
@@ -52,7 +34,7 @@ api.on('connected', async () => {
const min_ledger = (await api.getLedgerIndex()) + 1
const result = await api.request({
"command": "submit",
- "tx_blob": tx_blob
+ "tx_blob": signed.tx_blob
})
console.log("Tentative result code:", result.result.engine_result)
console.log("Tentative result message:", result.result.engine_result_message)
@@ -61,10 +43,10 @@ api.on('connected', async () => {
let has_final_status = false
api.request({
"command": "subscribe",
- "accounts": [wallet.classicAddress]
+ "accounts": [wallet.address]
})
api.connection.on("transaction", (event) => {
- if (event.transaction.hash == txID) {
+ if (event.transaction.hash == signed.hash) {
console.log("Transaction has executed!", event)
has_final_status = true
}
@@ -87,7 +69,7 @@ api.on('connected', async () => {
try {
const tx = await api.request({
command: "tx",
- transaction: txID,
+ transaction: signed.hash,
min_ledger: min_ledger,
max_ledger: max_ledger
})