-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxahauwallet.js
150 lines (126 loc) · 4.82 KB
/
xahauwallet.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// ******************************************************
// ************* Get the Preferred Network **************
// ******************************************************
function getNet() {
let net;
if (document.getElementById("tn").checked) net = "wss://xahau-test.net";
if (document.getElementById("mn").checked) net = "wss://xahau.network";
return net;
} // End of getNet()
// *******************************************************
// ************* Create XAHAU Testnet Account ************
// *******************************************************
async function getSome() {
const call = await window.fetch("https://xahau-test.net/newcreds", {
method: "POST",
});
const data = await call.json();
console.log(data);
standbyAccountField.value = data.address;
standbySeedField.value = data.secret;
standbyBalanceField.value = data.xrp;
seeds.value = standbySeedField.value;
standbyAmountField.value = "";
standbyDestinationField.value = "";
standbyResultField.value =
"New account created:" +
"\nAccount: " +
data.address +
"\nSeed: " +
data.secret +
"\nXAH: " +
data.xrp +
"\nHash: " +
data.hash +
"\nCode: " +
data.code;
}
// *******************************************************
// ************* Create XAHAU Mainnet Account **************
// *******************************************************
async function getAccount2() {
const wallet = xrpl.Wallet.generate("ed25519");
console.log(wallet);
standbyResultField.value =
"Creating a wallet...\n" + "Wallet created:\n" + JSON.stringify(wallet);
standbyAccountField.value = wallet.address;
standbySeedField.value = wallet.seed;
seeds.value = standbySeedField.value;
standbyBalanceField.value = "";
standbyAmountField.value = "";
standbyDestinationField.value = "";
} // End of getAccount2()
// *******************************************************
// ********** Get Accounts from Seeds ********************
// *******************************************************
async function getAccountsFromSeeds() {
let net = getNet();
const client = new xrpl.Client(net);
results = "Connecting to " + getNet() + "....";
standbyResultField.value = results;
await client.connect();
results += "\nConnected.\n";
standbyResultField.value = results;
try {
// -------------------------------------------------Find the test account wallets.
const standby_wallet = xrpl.Wallet.fromSeed(seeds.value);
// -------------------------------------------------------Get the current balance.
const standby_balance = await client.getXrpBalance(standby_wallet.address);
// ----------------------Populate the fields for Standby account.
standbyAccountField.value = standby_wallet.address;
standbySeedField.value = standby_wallet.seed;
standbyBalanceField.value = standby_balance;
standbyAmountField.value = "";
standbyDestinationField.value = "";
} catch (err) {
console.log("Error submitting transaction: ", err);
standbyResultField.value = err;
}
client.disconnect();
} // End of getAccountsFromSeeds()
// *******************************************************
// ******************** Send XAH *************************
// *******************************************************
async function sendXAHAU() {
results = "Connecting to the selected ledger.\n";
standbyResultField.value = results;
let net = getNet();
results = "Connecting to " + getNet() + "....";
const client = new xrpl.Client(net);
await client.connect();
results += "\nConnected. Sending XAH...";
standbyResultField.value = results;
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value);
const sendAmount = standbyAmountField.value;
results += "\nSending from account: " + standby_wallet.address;
standbyResultField.value = results;
if (net === "wss://xahau-test.net") {
networkID = 21338;
}
if (net === "wss://xahau.network") {
networkID = 21337;
}
// -------------------------------------------------------- Prepare transaction
const prepared = await client.autofill({
TransactionType: "Payment",
Account: standby_wallet.address,
Amount: xrpl.xrpToDrops(sendAmount),
Destination: standbyDestinationField.value,
NetworkID: networkID,
});
// ------------------------------------------------- Sign prepared instructions
const signed = standby_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);
standbyResultField.value = results;
standbyBalanceField.value = await client.getXrpBalance(
standby_wallet.address
);
client.disconnect();
} // End of sendXAHAU()
async function reload() {
window.location.reload();
}