mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-10 14:55:49 +00:00
Revise payment tutorials, add/remove screenshots
This commit is contained in:
28
_code-samples/modular-tutorials/send-xrp.js
Normal file
28
_code-samples/modular-tutorials/send-xrp.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// *******************************************************
|
||||
// ******************** Send XRP *************************
|
||||
// *******************************************************
|
||||
async function sendXRP() {
|
||||
const net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
await client.connect()
|
||||
let results = "\nConnected. Sending 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()
|
||||
} // End of sendXRP()
|
||||
Reference in New Issue
Block a user