// 1. Generate // 2. Connect // The code for these steps is handled by interactive-tutorial.js $(document).ready(() => { // 3. Check Sequence Number $("#check-sequence").click( async function(event) { const block = $(event.target).closest(".interactive-block") const address = get_address(event) if (!address) {return} // Wipe previous output block.find(".output-area").html("") block.find(".loader").show() const account_info = await api.request("account_info", {"account": address}) block.find(".loader").hide() block.find(".output-area").append( `
Current sequence:
${account_info.account_data.Sequence}
Prepared transaction:
${pretty_print(prepared.txJSON)}`)
let signed = api.sign(prepared.txJSON, secret)
block.find(".output-area").append(
`Transaction hash: ${signed.id}
Signed blob:
${tx_blob}`)
complete_step("Prepare & Sign")
})
// 5. Submit TicketCreate ------------------------------------------------------
$("#ticketcreate-submit").click( submit_handler )
// 6. Wait for Validation: handled by interactive-tutorial.js and by the
// generic submit handler in the previous step. --------------------------------
// Intermission ----------------------------------------------------------------
async function intermission_submit(event, tx_json) {
const secret = get_secret(event)
if (!secret) {return}
const block = $(event.target).closest(".interactive-block")
let prepared = await api.prepareTransaction(tx_json)
let signed = api.sign(prepared.txJSON, secret)
let prelim_result = await api.request("submit",
{"tx_blob": signed.signedTransaction})
block.find(".output-area").append(`${tx_json.TransactionType} ${prepared.instructions.sequence}: ${prelim_result.engine_result}
`) } $("#intermission-payment").click( async function(event) { const address = get_address(event) if (!address) {return} intermission_submit(event, { "TransactionType": "Payment", "Account": address, "Destination": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", // Testnet Faucet "Amount": api.xrpToDrops("201") }) complete_step("Intermission") }) $("#intermission-escrowcreate").click( async function(event) { const address = get_address(event) if (!address) {return} intermission_submit(event, { "TransactionType": "EscrowCreate", "Account": address, "Destination": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", // Genesis acct "Amount": api.xrpToDrops("0.13"), // Arbitrary amount "FinishAfter": api.iso8601ToRippleTime(Date()) + 30 // 30 seconds from now }) complete_step("Intermission") }) $("#intermission-accountset").click( async function(event) { const address = get_address(event) if (!address) {return} intermission_submit(event, { "TransactionType": "AccountSet", "Account": address }) complete_step("Intermission") }) // 7. Check Available Tickets -------------------------------------------------- $("#check-tickets").click( async function(event) { const block = $(event.target).closest(".interactive-block") const address = get_address(event) if (!address) {return} // Wipe previous output block.find(".output-area").html("") block.find(".loader").show() let response = await api.request("account_objects", { "account": address, "type": "ticket" }) block.find(".output-area").html( `${pretty_print(response)}`)
block.find(".loader").hide()
// Reset the next step's form & add these tickets
$("#ticket-selector .form-area").html("")
response.account_objects.forEach((ticket, i) => {
$("#ticket-selector .form-area").append(
`Prepared transaction:
${pretty_print(prepared_t.txJSON)}`)
let signed_t = api.sign(prepared_t.txJSON, secret)
block.find(".output-area").append(
`Transaction hash: ${signed_t.id}
${tx_blob_t}`)
// Update breadcrumbs & activate next step
complete_step("Prepare Ticketed Tx")
})
// 9. Submit Ticketed Transaction ----------------------------------------------
$("#ticketedtx-submit").click( submit_handler )
// 10. Wait for Validation (Again): handled by interactive-tutorial.js and by
// the generic submit handler in the previous step. --------------------------------
})