-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendTx1.js
125 lines (92 loc) · 3.29 KB
/
sendTx1.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
const Dash = require('dash');
const recipient = "ygv9AGM4P6XfpMPg5ndKVpBzX1hjo5Sw2T"
const satoshis = 1e6
const maxRetryCount = 20
let retryCounter = 0
let client, account;
const timeFunction = async (promiseToTime) => {
const timingStart = Date.now()
const promiseResult = await promiseToTime
const timing = (Date.now() - timingStart) / 1000
console.log(promiseResult, ` finished in ${timing}:>> `)
return promiseResult
}
let clientOpts = {
unsafeOptions: {
skipSynchronizationBeforeHeight: 495209,
},
dapiAddresses: [
'34.220.41.134',
'18.236.216.191',
'54.191.227.118',
],
wallet: {
// mnemonic: null
mnemonic: 'fever empty hotel donor chase funny photo honey economy near filter confirm' //receiving address yhehrX13jHPPanTxWiXxGEbz4S8RZ7PsbW
// mnemonic: 'best ridge office initial ski luggage flee kiwi basket brush pave number' // receiving address ygv9AGM4P6XfpMPg5ndKVpBzX1hjo5Sw2T
}
};
console.log('clientOpts :>> ', clientOpts);
const sleep = (ms) => new Promise((resolve)=>{setTimeout(resolve,ms)})
const sendTxLoop = async() => {
sendTx()
await sleep(60000)
sendTxLoop()
}
async function init() {
try {
retryCounter = 0
client = new Dash.Client(clientOpts);
console.log('mnemonic: ', client.wallet.exportWallet())
account = await timeFunction(client.wallet.getAccount());
const address = account.getUnusedAddress().address
console.log('receiving address:', address);
const accBalTotal = account.getTotalBalance();
const accBalUnconf = account.getUnconfirmedBalance()
const accBalConf = account.getConfirmedBalance()
console.log(`Total balance: ${accBalTotal}`)
console.log(`Unconfirmed balance: ${accBalUnconf}`)
console.log(`Confirmed balance: ${accBalConf}`)
console.log(Date(), "Staring sendTxLoop")
sendTxLoop()
}
catch (e) {
console.error(Date(), 'Init error', e)
console.dir(e, {depth: 100})
process.exit(1)
}
}
const sendTx = async () => {
try {
const accBalTotal = account.getTotalBalance();
const accBalUnconf = account.getUnconfirmedBalance()
const accBalConf = account.getConfirmedBalance()
console.log(`Total balance: ${accBalTotal}`)
console.log(`Unconfirmed balance: ${accBalUnconf}`)
console.log(`Confirmed balance: ${accBalConf}`)
const transaction = account.createTransaction({
recipients: [
{
recipient,
satoshis
},
]
});
const result = await timeFunction(account.broadcastTransaction(transaction))
console.log(Date(), 'Transaction broadcast!\nTransaction ID:', result);
return;
} catch (e) {
console.error(Date(),'sendTx Error',e)
console.dir(e, { depth: 100})
console.log('retryCounter :>> ', retryCounter);
retryCounter += 1
if (retryCounter >= maxRetryCount) {
process.exit(1)
} else {
console.log("Waiting 10 seconds until retry...")
await sleep(10000)
sendTx()
}
}
}
init()