mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 04:05:49 +00:00
73 lines
2.7 KiB
JavaScript
73 lines
2.7 KiB
JavaScript
// *******************************************************
|
|
// ***************** Create TrustLine ********************
|
|
// *******************************************************
|
|
|
|
async function createTrustLine() {
|
|
const net = getNet()
|
|
const client = new xrpl.Client(net)
|
|
await client.connect()
|
|
let results = "\nConnected. Creating trust line.\n"
|
|
resultField.value = results
|
|
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
|
const trustSet_tx = {
|
|
"TransactionType": "TrustSet",
|
|
"Account": accountAddressField.value,
|
|
"LimitAmount": {
|
|
"currency": currencyField.value,
|
|
"issuer": issuerField.value,
|
|
"value": amountField.value
|
|
}
|
|
}
|
|
const ts_prepared = await client.autofill(trustSet_tx)
|
|
const ts_signed = wallet.sign(ts_prepared)
|
|
resultField.value = results
|
|
const ts_result = await client.submitAndWait(ts_signed.tx_blob)
|
|
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
|
|
results += '\nTrustline established between account \n' +
|
|
accountAddressField.value + ' \n and account\n' + issuerField.value + '.'
|
|
resultField.value = results
|
|
} else {
|
|
results += `\nTransaction failed: ${ts_result.result.meta.TransactionResult}`
|
|
resultField.value = results
|
|
}
|
|
} //End of createTrustline()
|
|
|
|
// *******************************************************
|
|
// *************** Send Issued Currency ******************
|
|
// *******************************************************
|
|
|
|
async function sendCurrency() {
|
|
let net = getNet()
|
|
const client = new xrpl.Client(net)
|
|
results = 'Connecting to ' + getNet() + '....'
|
|
resultField.value = results
|
|
await client.connect()
|
|
results += '\nConnected.'
|
|
resultField.value = results
|
|
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
|
const send_currency_tx = {
|
|
"TransactionType": "Payment",
|
|
"Account": wallet.address,
|
|
"Amount": {
|
|
"currency": currencyField.value,
|
|
"value": amountField.value,
|
|
"issuer": issuerField.value
|
|
},
|
|
"Destination": destinationField.value
|
|
}
|
|
const pay_prepared = await client.autofill(send_currency_tx)
|
|
const pay_signed = wallet.sign(pay_prepared)
|
|
results += `\n\nSending ${amountField.value} ${currencyField.value} to ${destinationField.value} ...`
|
|
resultField.value = results
|
|
const pay_result = await client.submitAndWait(pay_signed.tx_blob)
|
|
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
|
|
results += 'Transaction succeeded.'
|
|
resultField.value = results
|
|
} else {
|
|
results += `\nTransaction failed: ${pay_result.result.meta.TransactionResult}`
|
|
resultField.value = results
|
|
}
|
|
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
|
client.disconnect()
|
|
} // end of sendCurrency()
|