Files
xrpl-dev-portal/content/_code-samples/escrow/js/cancel-escrow.js
2023-01-25 10:08:52 +00:00

40 lines
1.3 KiB
JavaScript

'use strict'
if (typeof module !== "undefined") {
// Use var here because const/let are block-scoped to the if statement.
var xrpl = require('xrpl')
}
const main = async () => {
try {
// Connect -------------------------------------------------------------------
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
// Get credentials from the Testnet Faucet ------------------------------------
console.log("Requesting an address from the Testnet faucet...");
const { wallet } = await client.fundWallet();
console.log("Wallet: ", wallet.address);
const escrowCancelTransaction = {
"Account": wallet.address,
"TransactionType": "EscrowCancel",
"Owner": wallet.address,
"OfferSequence": 34821001, // Sequence number
};
xrpl.validate(escrowCancelTransaction);
// Sign and submit the transaction --------------------------------------------
console.log('Signing and submitting the transaction:', JSON.stringify(escrowCancelTransaction, null, "\t"));
const response = await client.submitAndWait(escrowCancelTransaction, { wallet });
console.log(`Finished submitting! ${JSON.stringify(response.result, null, "\t")}`);
await client.disconnect();
} catch (error) {
console.log(error);
}
}
main()