-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
178 lines (159 loc) · 5.14 KB
/
Copy pathindex.js
File metadata and controls
178 lines (159 loc) · 5.14 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
require('colors');
const fs = require('fs');
const readlineSync = require('readline-sync');
const { displayHeader, checkBalance } = require('./src/utils');
const { createWallet, createContract } = require('./src/wallet');
const { claimFragmentz } = require('./src/claim');
const { RPC_URL } = require('./src/utils');
const { JsonRpcProvider, ethers } = require('ethers');
const moment = require('moment');
const { CronJob } = require('cron');
const CONTRACT_ADDRESS = '0xF0a66d18b46D4D5dd9947914ab3B2DDbdC19C2C0';
async function claimProcess(seedPhrasesOrKeys, method, provider, numClaims) {
for (const keyOrPhrase of seedPhrasesOrKeys) {
let wallet;
if (method === '0') {
wallet = createWallet(keyOrPhrase, provider);
} else {
wallet = createWallet(keyOrPhrase, provider);
}
const senderAddress = wallet.address;
console.log(`Processing transactions for address: ${senderAddress}`.cyan);
const contract = createContract(wallet, CONTRACT_ADDRESS);
try {
await claimFragmentz(contract, numClaims);
console.log(
`Successfully claimed ${numClaims} Fragmentz for ${senderAddress}`.green
);
} catch (error) {
console.log(
`[ ${moment().format(
'HH:mm:ss'
)} ] Error claiming Fragmentz for ${senderAddress}: ${error.message}`
.red
);
}
}
}
async function setupRecurringClaim(
seedPhrasesOrKeys,
method,
provider,
numClaims
) {
console.log('Setting up recurring claim every 12 hours...'.green);
const job = new CronJob('0 */12 * * *', async function () {
await claimProcess(seedPhrasesOrKeys, method, provider, numClaims);
console.log(
`[ ${moment().format('HH:mm:ss')} ] Recurring claim executed.`.green
);
});
job.start();
console.log('Cron job successfully set up.'.green);
}
async function main() {
displayHeader();
const provider = new JsonRpcProvider(RPC_URL);
while (true) {
const action = readlineSync.question(
'Enter 0 to check balance, 1 to claim Fragmentz, or 2 to exit: '
);
if (action === '2') {
console.log('Exiting...'.cyan);
break;
}
try {
if (action === '0') {
const privateKeys = JSON.parse(
fs.readFileSync('privateKeys.json', 'utf-8')
);
if (!Array.isArray(privateKeys) || privateKeys.length === 0) {
throw new Error(
'privateKeys.json is not set correctly or is empty'.red
);
}
for (const privateKey of privateKeys) {
const wallet = createWallet(privateKey, provider);
const senderAddress = wallet.address;
const balance = await checkBalance(provider, senderAddress);
console.log(
`Address: ${senderAddress} - Balance: ${ethers.formatEther(
balance
)} ETH`.yellow
);
console.log(
`Claim faucet here: https://rivalz2.hub.caldera.xyz/`.yellow
);
}
} else if (action === '1') {
const claimOption = readlineSync.question(
'Enter 1 for one-time claim, 2 for 12 hours recurring claim: '
);
const method = readlineSync.question(
'Enter 0 to use mnemonics, 1 to use private keys: '
);
let seedPhrasesOrKeys;
if (method === '0') {
seedPhrasesOrKeys = JSON.parse(
fs.readFileSync('accounts.json', 'utf-8')
);
if (
!Array.isArray(seedPhrasesOrKeys) ||
seedPhrasesOrKeys.length === 0
) {
throw new Error(
'accounts.json is not set correctly or is empty'.red
);
}
} else if (method === '1') {
seedPhrasesOrKeys = JSON.parse(
fs.readFileSync('privateKeys.json', 'utf-8')
);
if (
!Array.isArray(seedPhrasesOrKeys) ||
seedPhrasesOrKeys.length === 0
) {
throw new Error(
'privateKeys.json is not set correctly or is empty'.red
);
}
} else {
throw new Error('Invalid input method selected'.red);
}
const numClaims = readlineSync.questionInt(
'How many Fragmentz do you want to claim? '
);
await claimProcess(seedPhrasesOrKeys, method, provider, numClaims);
console.log('Initial claim completed.'.green);
if (claimOption === '2') {
await setupRecurringClaim(
seedPhrasesOrKeys,
method,
provider,
numClaims
);
console.log(
'Bot is now running in idle mode. It will perform claims every 12 hours.'
.green
);
break;
}
} else {
console.log(
'Invalid input. Please enter 0 to check balance, 1 to claim Fragmentz, or 2 to exit.'
.red
);
}
} catch (error) {
console.log(
`[ ${moment().format('HH:mm:ss')} ] Error in main loop: ${
error.message
}`.red
);
} finally {
console.log('All tasks completed!'.green);
console.log('Subscribe: https://t.me/crypttopiaa'.green);
}
}
}
main();