// 1. Generate // 2. Connect // The code for these steps is handled by interactive-tutorial.js $(document).ready(() => { const LLS_OFFSET = 75 // Expire unconfirmed transactions after about ~5 min // 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({ "command": "account_info", "account": address }) block.find(".loader").hide() block.find(".output-area").append( `
Current sequence:
${account_info.result.account_data.Sequence}
Prepared transaction:
${pretty_print(prepared)}`)
const {tx_blob, hash} = wallet.sign(prepared)
block.find(".output-area").append(
`Transaction hash: ${hash}
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 block = $(event.target).closest(".interactive-block")
const wallet = get_wallet(event)
if (!wallet) {return}
const prepared = await api.autofill(tx_json)
const {tx_blob, hash} = wallet.sign(prepared)
const prelim = await api.request({
"command": "submit",
"tx_blob": tx_blob
})
block.find(".output-area").append(`${prepared.TransactionType} ${prepared.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": xrpl.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": xrpl.xrpToDrops("0.13"), // Arbitrary amount "FinishAfter": xrpl.isoTimeToRippleTime(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({ "command": "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.result.account_objects.forEach((ticket, i) => {
$("#ticket-selector .form-area").append(
`Prepared transaction:
${pretty_print(prepared_t)}`)
const {tx_blob, hash} = wallet.sign(prepared_t)
block.find(".output-area").append(
`Transaction hash: ${hash}
${tx_blob}`)
// 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. --------------------------------
})