-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendXRP.ts
More file actions
76 lines (61 loc) · 2.18 KB
/
sendXRP.ts
File metadata and controls
76 lines (61 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as xrpl from 'xrpl';
import * as readlineSync from 'readline-sync';
function ask(question: string): string {
return readlineSync.question(question);
}
function askMasked(question: string): string {
return readlineSync.question(question, { hideEchoBack: true });
}
async function main() {
try {
// Connect to XRPL mainnet via xrplcluster
const client = new xrpl.Client('wss://xrplcluster.com/');
await client.connect();
console.log('Connected to XRPL mainnet.');
// Step 1: Prompt for amount
const amountXRP = ask('Enter the amount of XRP to send: ');
const amountDrops = (parseFloat(amountXRP) * 1000000).toString();
// Step 2: Prompt for destination
const destination = ask('Enter the destination address: ');
// Step 3: Prompt for seed phrase
const seed = askMasked('Enter your seed phrase: ');
// Create wallet from seed
const wallet = xrpl.Wallet.fromSeed(seed);
// Prepare transaction
const tx: xrpl.Payment = {
TransactionType: 'Payment',
Account: wallet.address,
Destination: destination,
Amount: amountDrops,
};
// Autofill transaction (fee, sequence, etc.)
const prepared = await client.autofill(tx);
// Summary
const feeXRP = (parseInt(prepared.Fee!) / 1000000).toFixed(6);
console.log('\n--- Transaction Summary ---');
console.log(`From: ${wallet.address}`);
console.log(`To: ${destination}`);
console.log(`Amount: ${amountXRP} XRP`);
console.log(`Fee: ${feeXRP} XRP`);
console.log(`Sequence: ${prepared.Sequence}`);
console.log('---------------------------');
// Confirmation
const confirm = ask('Do you want to submit this transaction? (y/n): ');
if (confirm.toLowerCase() !== 'y') {
console.log('Transaction cancelled.');
await client.disconnect();
return;
}
// Sign and submit
const signed = wallet.sign(prepared);
const result = await client.submit(signed.tx_blob);
console.log('Transaction submitted.');
console.log('Result:', result);
await client.disconnect();
} catch (error) {
console.error('Error:', error);
process.stdin.setRawMode(false);
process.stdin.pause();
}
}
main();