mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
code updates for xrpl.js 2.0 beta 5
This commit is contained in:
@@ -8,30 +8,13 @@ api.connect()
|
||||
api.on('connected', async () => {
|
||||
|
||||
// Get credentials from the Testnet Faucet -----------------------------------
|
||||
const wallet = await api.generateFaucetWallet()
|
||||
|
||||
console.log("Waiting until we have a validated starting sequence number...")
|
||||
// If you go too soon, the funding transaction might slip back a ledger and
|
||||
// then your starting Sequence number will be off. This is mostly relevant
|
||||
// when you want to use a Testnet account right after getting a reply from
|
||||
// the faucet.
|
||||
while (true) {
|
||||
try {
|
||||
await api.request({
|
||||
command: "account_info",
|
||||
account: wallet.classicAddress,
|
||||
ledger_index: "validated"
|
||||
})
|
||||
break
|
||||
} catch(e) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
}
|
||||
}
|
||||
console.log("Getting a wallet from the Testnet faucet...")
|
||||
const {wallet, balance} = await api.fundWallet()
|
||||
|
||||
// Prepare transaction -------------------------------------------------------
|
||||
const prepared = await api.autofill({
|
||||
"TransactionType": "Payment",
|
||||
"Account": wallet.classicAddress,
|
||||
"Account": wallet.address,
|
||||
"Amount": xrpl.xrpToDrops("22"),
|
||||
"Destination": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
|
||||
})
|
||||
@@ -41,10 +24,9 @@ api.on('connected', async () => {
|
||||
console.log("Transaction expires after ledger:", max_ledger)
|
||||
|
||||
// Sign prepared instructions ------------------------------------------------
|
||||
const tx_blob = wallet.signTransaction(prepared)
|
||||
const txID = xrpl.computeSignedTransactionHash(tx_blob)
|
||||
console.log("Identifying hash:", txID)
|
||||
console.log("Signed blob:", tx_blob)
|
||||
const signed = wallet.sign(prepared)
|
||||
console.log("Identifying hash:", signed.hash)
|
||||
console.log("Signed blob:", signed.tx_blob)
|
||||
|
||||
// Submit signed blob --------------------------------------------------------
|
||||
// The earliest ledger a transaction could appear in is the first ledger
|
||||
@@ -52,7 +34,7 @@ api.on('connected', async () => {
|
||||
const min_ledger = (await api.getLedgerIndex()) + 1
|
||||
const result = await api.request({
|
||||
"command": "submit",
|
||||
"tx_blob": tx_blob
|
||||
"tx_blob": signed.tx_blob
|
||||
})
|
||||
console.log("Tentative result code:", result.result.engine_result)
|
||||
console.log("Tentative result message:", result.result.engine_result_message)
|
||||
@@ -61,10 +43,10 @@ api.on('connected', async () => {
|
||||
let has_final_status = false
|
||||
api.request({
|
||||
"command": "subscribe",
|
||||
"accounts": [wallet.classicAddress]
|
||||
"accounts": [wallet.address]
|
||||
})
|
||||
api.connection.on("transaction", (event) => {
|
||||
if (event.transaction.hash == txID) {
|
||||
if (event.transaction.hash == signed.hash) {
|
||||
console.log("Transaction has executed!", event)
|
||||
has_final_status = true
|
||||
}
|
||||
@@ -87,7 +69,7 @@ api.on('connected', async () => {
|
||||
try {
|
||||
const tx = await api.request({
|
||||
command: "tx",
|
||||
transaction: txID,
|
||||
transaction: signed.hash,
|
||||
min_ledger: min_ledger,
|
||||
max_ledger: max_ledger
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user