-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissueTokenXRPTestnetSimple.js
More file actions
133 lines (117 loc) · 4.59 KB
/
issueTokenXRPTestnetSimple.js
File metadata and controls
133 lines (117 loc) · 4.59 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
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
const xrpl = require("xrpl");
const seed1 = "sEdSdfV2P7CNSKgJe7wj1B78d4jpSgL";
const seed2 = "sEd7JUaRebKNWsbJbN16bH8ntHsVTVN";
// Connect ---------------------------------------------------------------------
async function main() {
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233");
console.log("Connecting to Testnet...");
await client.connect();
const hot_wallet = xrpl.Wallet.fromSeed(seed1);
const cold_wallet = xrpl.Wallet.fromSeed(seed2);
console.log(
`Got hot address ${hot_wallet.address} and cold address ${cold_wallet.address}.`
);
// Configure issuer (cold address) settings ----------------------------------
const cold_settings_tx = {
TransactionType: "AccountSet",
Account: cold_wallet.address,
TickSize: 5,
Domain: "6578616D706C652E636F6D", // "example.com"
SetFlag: xrpl.AccountSetAsfFlags.asfDefaultRipple,
Flags: xrpl.AccountSetTfFlags.tfDisallowXRP,
};
const cst_prepared = await client.autofill(cold_settings_tx);
const cst_signed = cold_wallet.sign(cst_prepared);
console.log("Sending cold address AccountSet transaction...");
const cst_result = await client.submitAndWait(cst_signed.tx_blob);
if (cst_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(
`Transaction succeeded: https://test.bithomp.com/explorer/${cst_signed.hash}`
);
} else {
throw `Error sending transaction: ${cst_result}`;
}
// Configure hot address settings --------------------------------------------
const hot_settings_tx = {
TransactionType: "AccountSet",
Account: hot_wallet.address,
Domain: "6578616D706C652E636F6D", // "example.com"
};
const hst_prepared = await client.autofill(hot_settings_tx);
const hst_signed = hot_wallet.sign(hst_prepared);
console.log("Sending hot address AccountSet transaction...");
const hst_result = await client.submitAndWait(hst_signed.tx_blob);
if (hst_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(
`Transaction succeeded: https://test.bithomp.com/explorer/${hst_signed.hash}`
);
} else {
throw `Error sending transaction: ${hst_result.result.meta.TransactionResult}`;
}
// Create trust line from hot to cold address --------------------------------
const currency_code = "PUP";
const trust_set_tx = {
TransactionType: "TrustSet",
Account: hot_wallet.address,
LimitAmount: {
currency: currency_code,
issuer: cold_wallet.address,
value: "123456789", // Arbitrarily chosen
},
};
const ts_prepared = await client.autofill(trust_set_tx);
const ts_signed = hot_wallet.sign(ts_prepared);
console.log("Creating trust line from hot address to issuer...");
const ts_result = await client.submitAndWait(ts_signed.tx_blob);
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(
`Transaction succeeded: https://test.bithomp.com/explorer/${ts_signed.hash}`
);
} else {
throw `Error sending transaction: ${ts_result.result.meta.TransactionResult}`;
}
// Send token ----------------------------------------------------------------
let issue_quantity = "123456789";
const send_token_tx = {
TransactionType: "Payment",
Account: cold_wallet.address,
Amount: {
currency: currency_code,
value: issue_quantity,
issuer: cold_wallet.address,
},
Destination: hot_wallet.address,
};
const pay_prepared = await client.autofill(send_token_tx);
const pay_signed = cold_wallet.sign(pay_prepared);
console.log(
`Cold to hot - Sending ${issue_quantity} ${currency_code} to ${hot_wallet.address}...`
);
const pay_result = await client.submitAndWait(pay_signed.tx_blob);
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
console.log(
`Transaction succeeded: https://test.bithomp.com/explorer/${pay_signed.hash}`
);
} else {
console.log(pay_result);
throw `Error sending transaction: ${pay_result.result.meta.TransactionResult}`;
}
// Check balances ------------------------------------------------------------
console.log("Getting hot address balances...");
const hot_balances = await client.request({
command: "account_lines",
account: hot_wallet.address,
ledger_index: "validated",
});
console.log(hot_balances.result);
console.log("Getting cold address balances...");
const cold_balances = await client.request({
command: "gateway_balances",
account: cold_wallet.address,
ledger_index: "validated",
hotwallet: [hot_wallet.address],
});
console.log(JSON.stringify(cold_balances.result, null, 2));
client.disconnect();
} // End of main()
main();