mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-15 09:15:50 +00:00
Updates based on feedback
This commit is contained in:
@@ -6,7 +6,6 @@ function getNet() {
|
||||
let net
|
||||
if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233/"
|
||||
if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233/"
|
||||
const client = new xrpl.Client(net)
|
||||
return net
|
||||
} // End of getNet()
|
||||
|
||||
@@ -18,23 +17,36 @@ async function getAccount() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.`
|
||||
let faucetHost = null
|
||||
const my_wallet = (await client.fundWallet(null, { faucetHost})).wallet
|
||||
const newAccount = [my_wallet.address, my_wallet.seed]
|
||||
return (newAccount)
|
||||
client.disconnect()
|
||||
resultField.value = `===Getting Account===\n\nConnected to ${net}.`
|
||||
try {
|
||||
let faucetHost = null
|
||||
const my_wallet = (await client.fundWallet(null, { faucetHost})).wallet
|
||||
const newAccount = [my_wallet.address, my_wallet.seed]
|
||||
return (newAccount)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('===Error getting account:', error);
|
||||
results += `\nError: ${error.message}\n`
|
||||
resultField.value = results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await client.disconnect();
|
||||
}
|
||||
} // End of getAccount()
|
||||
|
||||
async function getNewAccount1() {
|
||||
account1address.value = "Getting new account."
|
||||
account1address.value = "=== Getting new account. ===\n\n"
|
||||
account1seed.value = ""
|
||||
const accountInfo= await getAccount()
|
||||
account1address.value = accountInfo[0]
|
||||
account1seed.value = accountInfo[1]
|
||||
}
|
||||
|
||||
async function getNewAccount2() {
|
||||
account2address.value = "Getting new account."
|
||||
account2address.value = "=== Getting new account. ===\n\n"
|
||||
account2seed.value = ""
|
||||
const accountInfo= await getAccount()
|
||||
account2address.value = accountInfo[0]
|
||||
account2seed.value = accountInfo[1]
|
||||
@@ -48,13 +60,26 @@ async function getAccountFromSeed(my_seed) {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = '\nConnected, finding wallet.\n'
|
||||
let results = '===Finding wallet.===\n\n'
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(my_seed)
|
||||
// ----------------------Populate the fields for left and right accounts.
|
||||
const address = wallet.address
|
||||
client.disconnect()
|
||||
return (address)
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(my_seed)
|
||||
const address = wallet.address
|
||||
results += "===Wallet found.===\n\n"
|
||||
results += "Account address: " + address + "\n\n"
|
||||
resultField.value = results
|
||||
return (address)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('===Error getting account from seed:', error);
|
||||
results += `\nError: ${error.message}\n`
|
||||
resultField.value = results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await client.disconnect();
|
||||
}
|
||||
} // End of getAccountFromSeed()
|
||||
|
||||
// *****************************************************
|
||||
@@ -120,15 +145,32 @@ function populate2() {
|
||||
}
|
||||
|
||||
// *******************************************************
|
||||
// **************** Get Xrp Balance *********************
|
||||
// **************** Get XRP Balance *********************
|
||||
// *******************************************************
|
||||
|
||||
async function getXrpBalance() {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
xrpBalanceField.value = await client.getXrpBalance(accountAddressField.value)
|
||||
client.disconnect()
|
||||
let results = `\n===Getting XRP balance...===\n\n`
|
||||
resultField.value = results
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const balance = await client.getXrpBalance(wallet.address)
|
||||
results += accountNameField.value + " current XRP balance: " + balance + "\n\n"
|
||||
xrpBalanceField.value = await client.getXrpBalance(accountAddressField.value)
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error getting XRP balance:', error);
|
||||
results += `\nError: ${error.message}\n`
|
||||
resultField.value = results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await client.disconnect();
|
||||
}
|
||||
} // End of getXrpBalance()
|
||||
|
||||
// *******************************************************
|
||||
@@ -138,21 +180,29 @@ async function getXrpBalance() {
|
||||
async function getTokenBalance() {
|
||||
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)
|
||||
results= "\nGetting account balance...\n"
|
||||
const balance = await client.request({
|
||||
command: "gateway_balances",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated",
|
||||
})
|
||||
results += JSON.stringify(balance.result, null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
let results = `===Connected to ${net}.===\n===Getting account token balance...===\n\n`
|
||||
resultField.value += results
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const balance = await client.request({
|
||||
command: "gateway_balances",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated",
|
||||
})
|
||||
results = accountNameField.value + "\'s token balance(s): " + JSON.stringify(balance.result, null, 2) + "\n"
|
||||
resultField.value += results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error getting token balance:', error);
|
||||
results = `\nError: ${error.message}\n`
|
||||
resultField.value += results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await client.disconnect();
|
||||
}
|
||||
} // End of getTokenBalance()
|
||||
|
||||
|
||||
@@ -8,42 +8,43 @@ async function createConditionalEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}, creating conditional escrow.\n`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
|
||||
wallet.address
|
||||
|
||||
let results = `===Connected to ${net}===\n===Creating conditional escrow.===\n\n`
|
||||
resultField.value = results
|
||||
let escrow_cancel_date = new Date()
|
||||
escrow_cancel_date = addSeconds(parseInt(escrowCancelDateField.value))
|
||||
|
||||
// ------------------------------------------------------- Prepare transaction
|
||||
try {
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"CancelAfter": escrow_cancel_date,
|
||||
"Condition": escrowConditionField.value
|
||||
})
|
||||
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"CancelAfter": escrow_cancel_date,
|
||||
"Condition": escrowConditionField.value
|
||||
})
|
||||
|
||||
// ------------------------------------------------ Sign prepared instructions
|
||||
const signed = wallet.sign(escrowTx)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nSequence Number (Save!): " + tx.result.tx_json.Sequence
|
||||
results += "\n\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
|
||||
// ----------------------------------------------Disconnect from the XRP Ledger
|
||||
client.disconnect()
|
||||
// ------------------------------------------------ Sign prepared instructions
|
||||
const signed = wallet.sign(escrowTx)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results = "\n=== *** Sequence Number (Save!): " + tx.result.tx_json.Sequence
|
||||
results += "\n\n===Balance changes===\n" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value += results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
// -------------------------------------------------------- Disconnect
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of createTimeEscrow()
|
||||
|
||||
// *******************************************************
|
||||
@@ -54,31 +55,32 @@ async function finishConditionalEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}, fulfilling conditional escrow.\n`
|
||||
let results = `===Connected to ${net}===\n===Fulfilling conditional escrow.===\n`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
|
||||
// ------------------------------------------------------- Prepare transaction
|
||||
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value),
|
||||
"Condition": escrowConditionField.value,
|
||||
"Fulfillment": escrowFulfillmentField.value
|
||||
})
|
||||
|
||||
// ------------------------------------------------ Sign prepared instructions
|
||||
const signed = wallet.sign(prepared)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
|
||||
} // End of finishEscrow()
|
||||
try {
|
||||
// ------------------------------------------------------- Prepare transaction
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value),
|
||||
"Condition": escrowConditionField.value,
|
||||
"Fulfillment": escrowFulfillmentField.value
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Balance changes===" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message + ".===\n"
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
// -------------------------------------------------------- Disconnect
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of finisConditionalEscrow()
|
||||
@@ -2,56 +2,54 @@
|
||||
*********** Create Offer **********
|
||||
**********************************/
|
||||
|
||||
async function createOffer() {
|
||||
async function createOffer() {
|
||||
let net = getNet()
|
||||
let results = 'Connecting to ' + net + '....\n'
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
|
||||
results += "Connected. Getting wallets.\n"
|
||||
let results = `===Connected to ${net}, getting wallet....===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += accountNameField.value + " account address: " + wallet.address + "\n"
|
||||
resultField.value = results
|
||||
|
||||
|
||||
if (getCurrencyField.value == 'XRP') {
|
||||
takerGets = getAmountField.value
|
||||
} else {
|
||||
takerGetsString = '{"currency": "' + getCurrencyField.value +'",\n' +
|
||||
try {
|
||||
if (getCurrencyField.value == 'XRP') {
|
||||
takerGets = xrpl.xrpToDrops(getAmountField.value)
|
||||
}
|
||||
else {
|
||||
takerGetsString = '{"currency": "' + getCurrencyField.value + '",\n' +
|
||||
'"issuer": "' + getIssuerField.value + '",\n' +
|
||||
'"value": "' + getAmountField.value + '"}'
|
||||
takerGets = JSON.parse(takerGetsString)
|
||||
}
|
||||
takerGets = JSON.parse(takerGetsString)
|
||||
}
|
||||
|
||||
if (payCurrencyField.value == 'XRP') {
|
||||
takerPays = payAmountField.value
|
||||
} else {
|
||||
takerPaysString = '{"currency": "' + payCurrencyField.value + '",\n' +
|
||||
'"issuer": "' + payIssuerField.value + '",\n' +
|
||||
'"value": "' + payAmountField.value + '"}'
|
||||
takerPays = JSON.parse(takerPaysString)
|
||||
if (payCurrencyField.value == 'XRP') {
|
||||
takerPays = xrpl.xrpToDrops(payAmountField.value)
|
||||
} else {
|
||||
takerPaysString = '{"currency": "' + payCurrencyField.value + '",\n' +
|
||||
'"issuer": "' + payIssuerField.value + '",\n' +
|
||||
'"value": "' + payAmountField.value + '"}'
|
||||
takerPays = JSON.parse(takerPaysString)
|
||||
}
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "OfferCreate",
|
||||
"Account": wallet.address,
|
||||
"TakerGets": takerGets,
|
||||
"TakerPays": takerPays
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results = '\n\n===Offer created===\n\n' +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value += results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
} catch (err) {
|
||||
console.error('Error creating offer:', err);
|
||||
results = `\nError: ${err.message}\n`
|
||||
resultField.value += results
|
||||
throw err; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
client.disconnect()
|
||||
}
|
||||
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "OfferCreate",
|
||||
"Account": wallet.address,
|
||||
"TakerGets": takerGets,
|
||||
"TakerPays": takerPays
|
||||
})
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared)
|
||||
results += "\nSubmitting transaction...."
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
getOffers()
|
||||
client.disconnect()
|
||||
} // End of createOffer()
|
||||
|
||||
/***********************************
|
||||
@@ -60,66 +58,64 @@
|
||||
|
||||
async function getOffers() {
|
||||
let net = getNet()
|
||||
let results = 'Connecting to ' + net + '....\n'
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results += "Connected.\n"
|
||||
let results = `===Connected to ' + ${net}, getting offers....===\n`
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += accountNameField.value + " account: " + wallet.address
|
||||
// -------------------------------------------------------- Prepare request
|
||||
|
||||
results += '\n\n*** Offers ***\n'
|
||||
resultField.value = results
|
||||
results += '\n\n=== Offers ===\n'
|
||||
let offers
|
||||
try {
|
||||
const offers = await client.request({
|
||||
offers = await client.request({
|
||||
method: "account_offers",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated"
|
||||
})
|
||||
results += JSON.stringify(offers,null,2)
|
||||
results = JSON.stringify(offers, null, 2)
|
||||
resultField.value += results
|
||||
} catch (err) {
|
||||
results += err
|
||||
console.error('Error getting offers:', err);
|
||||
results = `\nError: ${err.message}\n`
|
||||
resultField.value += results
|
||||
throw err; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
}// End of getOffers()
|
||||
|
||||
/***********************************
|
||||
*********** Cancel Offer **********
|
||||
**********************************/
|
||||
|
||||
async function cancelOffer() {
|
||||
let results = "Connecting to the selected ledger.\n"
|
||||
resultField.value = results
|
||||
let net = getNet()
|
||||
results += 'Connecting to ' + net + '....\n'
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
|
||||
results += "Connected.\n"
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += "wallet.address: = " + wallet.address
|
||||
resultField.value = results
|
||||
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
/* OfferSequence is the Seq value when you getOffers. */
|
||||
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "OfferCancel",
|
||||
"Account": wallet.address,
|
||||
"OfferSequence": parseInt(offerSequenceField.value)
|
||||
})
|
||||
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared)
|
||||
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
|
||||
results += "\nBalance changes: \n" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
async function cancelOffer() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `===Connected to ${net}, canceling offer.===\n`
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // End of cancelOffer()
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
try {
|
||||
// OfferSequence is the _seq_ value from getOffers.
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "OfferCancel",
|
||||
"Account": wallet.address,
|
||||
"OfferSequence": parseInt(offerSequenceField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nOffer canceled. Balance changes: \n" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Error canceling offer:', err);
|
||||
results = `\nError: ${err.message}\n`
|
||||
resultField.value += results
|
||||
throw err; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
client.disconnect()
|
||||
}
|
||||
}// End of cancelOffer()
|
||||
|
||||
@@ -15,37 +15,40 @@ function addSeconds(numOfSeconds, date = new Date()) {
|
||||
// *******************************************************
|
||||
|
||||
async function createTimeBasedEscrow() {
|
||||
|
||||
//-------------------------------------------- Prepare Finish and Cancel Dates
|
||||
|
||||
let escrow_finish_date = new Date()
|
||||
let escrow_cancel_date = new Date()
|
||||
escrow_finish_date = addSeconds(parseInt(escrowFinishTimeField.value))
|
||||
escrow_cancel_date = addSeconds(parseInt(escrowCancelTimeField.value))
|
||||
|
||||
//------------------------------------------------------Connect to the Ledger
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}.\nCreating time-based escrow.\n`
|
||||
let results = `===Connected to ${net}.===\n\n===Creating time-based escrow.===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
resultField.value = results
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"FinishAfter": escrow_finish_date,
|
||||
"CancelAfter": escrow_cancel_date
|
||||
})
|
||||
const signed = wallet.sign(escrowTx)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nSuccess! Save this sequence number: " + tx.result.tx_json.Sequence
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
const escrowTx = await client.autofill({
|
||||
"TransactionType": "EscrowCreate",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value,
|
||||
"FinishAfter": escrow_finish_date,
|
||||
"CancelAfter": escrow_cancel_date
|
||||
})
|
||||
const signed = wallet.sign(escrowTx)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Success! === *** Save this sequence number: " + tx.result.tx_json.Sequence
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of createTimeEscrow()
|
||||
|
||||
// *******************************************************
|
||||
@@ -56,24 +59,30 @@ async function finishTimeBasedEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}. Finishing escrow....`
|
||||
let results = `===Connected to ${net}. Finishing escrow.===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
results += "\nwallet.address: = " + wallet.address
|
||||
resultField.value = results
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
try {
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowFinish",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Balance changes===" +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message + "==="
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of finishTimeBasedEscrow()
|
||||
|
||||
// *******************************************************
|
||||
@@ -83,21 +92,28 @@ async function finishTimeBasedEscrow() {
|
||||
async function getEscrows() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.\nGetting account escrows...\n`
|
||||
await client.connect()
|
||||
let results = `\n===Connected to ${net}.\nGetting account escrows.===\n`
|
||||
resultField.value = results
|
||||
const escrow_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "escrow"
|
||||
})
|
||||
results += JSON.stringify(escrow_objects.result, null, 2)
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
} // End of getEscrows()
|
||||
|
||||
try {
|
||||
const escrow_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": accountAddressField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "escrow"
|
||||
})
|
||||
results += JSON.stringify(escrow_objects.result, null, 2)
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\nError: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// *******************************************************
|
||||
// ************** Get Transaction Info *******************
|
||||
@@ -106,18 +122,25 @@ async function getEscrows() {
|
||||
async function getTransaction() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.\nGetting transaction information...\n`
|
||||
await client.connect()
|
||||
let results = `\n===Connected to ${net}.===\n===Getting transaction information.===\n`
|
||||
resultField.value = results
|
||||
const tx_info = await client.request({
|
||||
"id": 1,
|
||||
"command": "tx",
|
||||
"transaction": transactionField.value,
|
||||
})
|
||||
results += JSON.stringify(tx_info.result, null, 2)
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
|
||||
try {
|
||||
const tx_info = await client.request({
|
||||
"id": 1,
|
||||
"command": "tx",
|
||||
"transaction": transactionField.value,
|
||||
})
|
||||
results += JSON.stringify(tx_info.result, null, 2)
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\nError: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of getTransaction()
|
||||
|
||||
// *******************************************************
|
||||
@@ -128,20 +151,27 @@ async function cancelEscrow() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}. Cancelling escrow....`
|
||||
let results = `\n===Connected to ${net}. Cancelling escrow.===`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowCancel",
|
||||
"Account": wallet.address,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\nBalance changes: " +
|
||||
try {
|
||||
const prepared = await client.autofill({
|
||||
"TransactionType": "EscrowCancel",
|
||||
"Account": accountAddressField.value,
|
||||
"Owner": escrowOwnerField.value,
|
||||
"OfferSequence": parseInt(escrowSequenceNumberField.value)
|
||||
})
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const signed = wallet.sign(prepared)
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += "\n===Balance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
resultField.value = results
|
||||
}
|
||||
catch (error) {
|
||||
results += "\n===Error: " + error.message
|
||||
resultField.value = results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
}
|
||||
@@ -5,39 +5,43 @@ async function sendCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
results = `\n===Connected to ${net}.===\n===Sending check.===\n`
|
||||
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
|
||||
}
|
||||
try {
|
||||
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 = '\n===Sending ' + 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\n'
|
||||
resultField.value += JSON.stringify(check_result.result, null, 2)
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
results = `Error sending transaction: ${error}`
|
||||
resultField.value += results
|
||||
}
|
||||
const send_check_tx = {
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": wallet.address,
|
||||
"SendMax": check_amount,
|
||||
"Destination": destinationField.value
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
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()
|
||||
|
||||
// *******************************************************
|
||||
@@ -48,17 +52,24 @@ async function getChecks() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `\nConnected to ${net}.`
|
||||
let results = `\n===Connected to ${net}.===\n===Getting account checks.===\n\n`
|
||||
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()
|
||||
try {
|
||||
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)
|
||||
} catch (error) {
|
||||
results = `Error getting checks: ${error}`
|
||||
resultField.value += results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
} // End of getChecks()
|
||||
|
||||
// *******************************************************
|
||||
@@ -69,39 +80,41 @@ async function cashCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
results = `\n===Connected to ${net}.===\n===Cashing check.===\n`
|
||||
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
|
||||
}
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
let 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
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
} catch (error) {
|
||||
results = `Error sending transaction: ${error}`
|
||||
resultField.value += results
|
||||
}
|
||||
const cash_check_tx = {
|
||||
"TransactionType": "CheckCash",
|
||||
"Account": wallet.address,
|
||||
"Amount": check_amount,
|
||||
"CheckID": checkIdField.value
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
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()
|
||||
|
||||
// *******************************************************
|
||||
@@ -112,28 +125,28 @@ async function cancelCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
results = `\nConnected to ${net}.`
|
||||
results = `\n===Connected to ${net}.===\n===Cancelling check.===\n`
|
||||
resultField.value = results
|
||||
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
|
||||
const cancel_check_tx = {
|
||||
"TransactionType": "CheckCancel",
|
||||
"Account": wallet.address,
|
||||
"CheckID": checkIdField.value
|
||||
try {
|
||||
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)
|
||||
const check_result = await client.submitAndWait(cancel_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += `===Transaction succeeded===\n${check_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
} catch (error) {
|
||||
results = `Error sending transaction: ${error}`
|
||||
resultField.value += results
|
||||
}
|
||||
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
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
} // end of cancelCheck()
|
||||
|
||||
@@ -8,27 +8,39 @@ async function createTrustLine() {
|
||||
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
|
||||
try {
|
||||
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 += '\n===Trustline established between account\n' +
|
||||
accountAddressField.value + "\nand account\n" + issuerField.value + '.'
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\n===Transaction failed: ${ts_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
}
|
||||
}
|
||||
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 + '.'
|
||||
catch (error) {
|
||||
console.error('Error creating trust line:', error);
|
||||
results += `\n===Error: ${error.message}\n`
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${ts_result.result.meta.TransactionResult}`
|
||||
resultField.value = results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await client.disconnect();
|
||||
}
|
||||
} //End of createTrustline()
|
||||
|
||||
@@ -44,29 +56,41 @@ async function sendCurrency() {
|
||||
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
|
||||
try {
|
||||
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\n===Sending ${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.'
|
||||
results += '\n===Transaction succeeded.'
|
||||
resultField.value = results
|
||||
getTokenBalance()
|
||||
} else {
|
||||
results += `\nTransaction failed: ${pay_result.result.meta.TransactionResult}`
|
||||
results += `\n===Transaction failed: ${pay_result.result.meta.TransactionResult}\n`
|
||||
resultField.value = results
|
||||
}
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error sending transaction:', error);
|
||||
results += `\nError: ${error.message}\n`
|
||||
resultField.value = results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await client.disconnect();
|
||||
}
|
||||
} // end of sendCurrency()
|
||||
|
||||
@@ -6,35 +6,36 @@ async function sendMPT() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}....`
|
||||
let results = `===Connected to ${net}. Sending MPT.===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpt_issuance_id = mptIdField.value
|
||||
const mpt_quantity = amountField.value
|
||||
const send_mpt_tx = {
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": {
|
||||
"mpt_issuance_id": mpt_issuance_id,
|
||||
"value": mpt_quantity,
|
||||
},
|
||||
"Destination": destinationField.value,
|
||||
}
|
||||
const pay_prepared = await client.autofill(send_mpt_tx)
|
||||
const pay_signed = wallet.sign(pay_prepared)
|
||||
results += `\n\nSending ${mpt_quantity} ${mpt_issuance_id} 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.\n\n'
|
||||
results += JSON.stringify(pay_result.result, null, 2)
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${pay_result.result.meta.TransactionResult}\n\n`
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpt_issuance_id = mptIdField.value
|
||||
const mpt_quantity = amountField.value
|
||||
const send_mpt_tx = {
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": {
|
||||
"mpt_issuance_id": mpt_issuance_id,
|
||||
"value": mpt_quantity,
|
||||
},
|
||||
"Destination": destinationField.value,
|
||||
}
|
||||
const pay_prepared = await client.autofill(send_mpt_tx)
|
||||
const pay_signed = wallet.sign(pay_prepared)
|
||||
results = `\n===Sending ${mpt_quantity} ${mpt_issuance_id} to ${destinationField.value} ...`
|
||||
resultField.value += results
|
||||
const pay_result = await client.submitAndWait(pay_signed.tx_blob)
|
||||
results = '\n\n===Transaction succeeded.\n'
|
||||
results += JSON.stringify(pay_result.result, null, 2)
|
||||
resultField.value = results
|
||||
resultField.value += results
|
||||
} catch (error) {
|
||||
results = `Error sending MPT: ${error}`
|
||||
resultField.value += results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
client.disconnect()
|
||||
} // end of sendMPT()
|
||||
|
||||
// *******************************************************
|
||||
@@ -45,27 +46,35 @@ async function getMPTs() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
let results = `Connected to ${net}....`
|
||||
resultField.value = results
|
||||
const mpts = await client.request({
|
||||
command: "account_objects",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated",
|
||||
type: "mptoken"
|
||||
})
|
||||
let JSONString = JSON.stringify(mpts.result, null, 2)
|
||||
let JSONParse = JSON.parse(JSONString)
|
||||
let numberOfMPTs = JSONParse.account_objects.length
|
||||
let x = 0
|
||||
while (x < numberOfMPTs){
|
||||
results += "\n\nMPT Issuance ID: " + JSONParse.account_objects[x].MPTokenIssuanceID
|
||||
+ "\nMPT Amount: " + JSONParse.account_objects[x].MPTAmount
|
||||
x++
|
||||
let results = ''
|
||||
resultField.value = `===Connected to ${net}. Getting MPTs.===`
|
||||
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpts = await client.request({
|
||||
command: "account_objects",
|
||||
account: wallet.address,
|
||||
ledger_index: "validated",
|
||||
type: "mptoken"
|
||||
})
|
||||
let JSONString = JSON.stringify(mpts.result, null, 2)
|
||||
let JSONParse = JSON.parse(JSONString)
|
||||
let numberOfMPTs = JSONParse.account_objects.length
|
||||
let x = 0
|
||||
while (x < numberOfMPTs){
|
||||
results += "\n\n===MPT Issuance ID: " + JSONParse.account_objects[x].MPTokenIssuanceID
|
||||
+ "\n===MPT Amount: " + JSONParse.account_objects[x].MPTAmount
|
||||
x++
|
||||
}
|
||||
results += "\n\n" + JSONString
|
||||
resultField.value += results
|
||||
} catch (error) {
|
||||
results = `===Error getting MPTs: ${error}`
|
||||
resultField.value += results
|
||||
}
|
||||
finally {
|
||||
client.disconnect()
|
||||
}
|
||||
results += "\n\n" + JSONString
|
||||
resultField.value = results
|
||||
client.disconnect()
|
||||
} // End of getMPTs()
|
||||
|
||||
// **********************************************************************
|
||||
@@ -76,25 +85,28 @@ async function authorizeMPT() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = `Connected to ${net}....`
|
||||
let results = `===Connected to ${net}. Authorizing MPT.===\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpt_issuance_id = mptIdField.value
|
||||
const auth_mpt_tx = {
|
||||
"TransactionType": "MPTokenAuthorize",
|
||||
"Account": wallet.address,
|
||||
"MPTokenIssuanceID": mpt_issuance_id,
|
||||
}
|
||||
const auth_prepared = await client.autofill(auth_mpt_tx)
|
||||
const auth_signed = wallet.sign(auth_prepared)
|
||||
results += `\n\nSending authorization...`
|
||||
resultField.value = results
|
||||
const auth_result = await client.submitAndWait(auth_signed.tx_blob)
|
||||
if (auth_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += `\nTransaction succeeded`
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const mpt_issuance_id = mptIdField.value
|
||||
const auth_mpt_tx = {
|
||||
"TransactionType": "MPTokenAuthorize",
|
||||
"Account": wallet.address,
|
||||
"MPTokenIssuanceID": mpt_issuance_id,
|
||||
}
|
||||
const auth_prepared = await client.autofill(auth_mpt_tx)
|
||||
const auth_signed = wallet.sign(auth_prepared)
|
||||
results += `\n\n===Sending authorization.===\n`
|
||||
resultField.value = results
|
||||
} else {
|
||||
results += `\nTransaction failed: ${auth_result.result.meta.TransactionResult}`
|
||||
const auth_result = await client.submitAndWait(auth_signed.tx_blob)
|
||||
results = '\n===Transaction succeeded===\n\n'
|
||||
resultField.value += results
|
||||
results += `\n\n` + JSON.stringify(auth_result.result, null, 2)
|
||||
} catch (error) {
|
||||
results = `===Error authorizing MPT: ${error}`
|
||||
resultField.value = results
|
||||
} finally {
|
||||
resultField.value = results
|
||||
}
|
||||
client.disconnect()
|
||||
|
||||
@@ -5,24 +5,33 @@ async function sendXRP() {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = "\nConnected. Sending XRP.\n"
|
||||
let results = `===Connected to ${net}.===\n\nSending XRP.\n`
|
||||
resultField.value = results
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
const prepared_tx = await client.autofill({
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value
|
||||
})
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared_tx)
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results = "\nBalance changes: " +
|
||||
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
client.disconnect()
|
||||
try {
|
||||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
|
||||
const sendAmount = amountField.value
|
||||
// -------------------------------------------------------- Prepare transaction
|
||||
const prepared_tx = await client.autofill({
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops(sendAmount),
|
||||
"Destination": destinationField.value
|
||||
})
|
||||
// ------------------------------------------------- Sign prepared instructions
|
||||
const signed = wallet.sign(prepared_tx)
|
||||
// -------------------------------------------------------- Submit signed blob
|
||||
const tx = await client.submitAndWait(signed.tx_blob)
|
||||
results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
|
||||
resultField.value = results
|
||||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address))
|
||||
} catch (error) {
|
||||
console.error('Error sending transaction:', error);
|
||||
results += `\nError: ${error.message}\n`
|
||||
resultField.value = results
|
||||
throw error; // Re-throw the error to be handled by the caller
|
||||
}
|
||||
finally {
|
||||
// Disconnect from the client
|
||||
await xrplClient.disconnect();
|
||||
}
|
||||
} // End of sendXRP()
|
||||
Reference in New Issue
Block a user