mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 20:25:51 +00:00
Revise payment tutorials, add/remove screenshots
This commit is contained in:
139
_code-samples/modular-tutorials/send-checks.js
Normal file
139
_code-samples/modular-tutorials/send-checks.js
Normal file
@@ -0,0 +1,139 @@
|
||||
// *******************************************************
|
||||
// ***************** Send Check **************************
|
||||
// *******************************************************
|
||||
async function sendCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
let check_amount = amountField.value
|
||||
if (currencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"currency": currencyField.value,
|
||||
"value": amountField.value,
|
||||
"issuer": wallet.address
|
||||
}
|
||||
}
|
||||
const send_check_tx = {
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": wallet.address,
|
||||
"SendMax": check_amount,
|
||||
"Destination": destinationField.value
|
||||
}
|
||||
const check_prepared = await client.autofill(send_check_tx)
|
||||
const check_signed = wallet.sign(check_prepared)
|
||||
results += '\nSending ' + amountField.value + ' ' + currencyField.value + ' to ' +
|
||||
destinationField.value + '...\n'
|
||||
resultField.value = results
|
||||
const check_result = await client.submitAndWait(check_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded:\n'
|
||||
resultField.value += JSON.stringify(check_result.result, null, 2)
|
||||
} else {
|
||||
results += `Error sending transaction: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of sendCheck()
|
||||
|
||||
// *******************************************************
|
||||
// ********************* Get Checks **********************
|
||||
// *******************************************************
|
||||
|
||||
async function getChecks() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
const check_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "check"
|
||||
})
|
||||
resultField.value = JSON.stringify(check_objects.result, null, 2)
|
||||
client.disconnect()
|
||||
} // End of getChecks()
|
||||
|
||||
// *******************************************************
|
||||
// ******************** Cash Check **********************
|
||||
// *******************************************************
|
||||
|
||||
async function cashCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
var check_amount = amountField.value
|
||||
|
||||
if (currencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"value": amountField.value,
|
||||
"currency": currencyField.value,
|
||||
"issuer": issuerField.value
|
||||
}
|
||||
}
|
||||
const cash_check_tx = {
|
||||
"TransactionType": "CheckCash",
|
||||
"Account": wallet.address,
|
||||
"Amount": check_amount,
|
||||
"CheckID": checkIdField.value
|
||||
}
|
||||
const cash_prepared = await client.autofill(cash_check_tx)
|
||||
const cash_signed = wallet.sign(cash_prepared)
|
||||
results += ' Receiving ' + amountField.value + ' ' + currencyField.value + '.\n'
|
||||
resultField.value = results
|
||||
const check_result = await client.submitAndWait(cash_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded:\n' + JSON.stringify(check_result.result, null, 2)
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `Error sending transaction: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of cashCheck()
|
||||
|
||||
// *******************************************************
|
||||
// **************** Cancel Check *************************
|
||||
// *******************************************************
|
||||
|
||||
async function cancelCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
|
||||
const cancel_check_tx = {
|
||||
"TransactionType": "CheckCancel",
|
||||
"Account": wallet.address,
|
||||
"CheckID": checkIdField.value
|
||||
}
|
||||
const cancel_prepared = await client.autofill(cancel_check_tx)
|
||||
const cancel_signed = wallet.sign(cancel_prepared)
|
||||
results += ' Cancelling check.\n'
|
||||
resultField.value = results
|
||||
const check_result = await client.submitAndWait(cancel_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += `Transaction succeeded: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `Error sending transaction: ${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of cancelCheck()
|
||||
Reference in New Issue
Block a user