-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
145 lines (121 loc) · 4.22 KB
/
index.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
const { ethers } = require('ethers');
const colors = require('colors');
const fs = require('fs');
const readlineSync = require('readline-sync');
const checkBalance = require('./src/checkBalance');
const displayHeader = require('./src/displayHeader');
const sleep = require('./src/sleep');
const rpcUrl = fs.readFileSync('rpc.txt', 'utf8').trim();
const main = async () => {
displayHeader();
const privateKeys = JSON.parse(fs.readFileSync('privateKeys.json'));
const provider = new ethers.JsonRpcProvider(rpcUrl);
for (const privateKey of privateKeys) {
const wallet = new ethers.Wallet(privateKey, provider);
const senderAddress = wallet.address;
console.log(
colors.cyan(`Processing transactions for address: ${senderAddress}`)
);
let senderBalance = await checkBalance(provider, senderAddress);
if (senderBalance < ethers.parseUnits('0.01', 'ether')) {
console.log(colors.red('BOT stopped. Insufficient or zero balance.'));
continue;
}
let continuePrintingBalance = true;
const printSenderBalance = async () => {
while (continuePrintingBalance) {
senderBalance = await checkBalance(provider, senderAddress);
console.log(
colors.blue(
`Current Balance: ${ethers.formatUnits(senderBalance, 'ether')} ETH`
)
);
if (senderBalance < ethers.parseUnits('0.01', 'ether')) {
console.log(colors.red('Insufficient balance for transactions.'));
continuePrintingBalance = false;
}
await sleep(5000);
}
};
printSenderBalance();
const transactionCount = readlineSync.questionInt(
`Enter the number of transactions you want to send for address ${senderAddress}: `
);
console.log();
for (let i = 1; i <= transactionCount; i++) {
const receiverWallet = ethers.Wallet.createRandom();
const receiverAddress = receiverWallet.address;
console.log(colors.white(`\nGenerated address ${i}: ${receiverAddress}`));
const amountToSend = ethers.parseUnits(
(Math.random() * (0.0001 - 0.00001) + 0.00001).toFixed(8).toString(),
'ether'
);
const gasPrice = ethers.parseUnits(
(Math.random() * (15 - 9) + 9).toFixed(2).toString(),
'gwei'
);
const transaction = {
to: receiverAddress,
value: amountToSend,
gasLimit: 21000,
gasPrice: gasPrice,
chainId: 11155111,
};
const tx = await wallet.sendTransaction(transaction);
console.log(colors.white(`Transaction ${i}:`));
console.log(colors.white(` Hash: ${colors.green(tx.hash)}`));
console.log(colors.white(` From: ${colors.green(senderAddress)}`));
console.log(colors.white(` To: ${colors.green(receiverAddress)}`));
console.log(
colors.white(
` Amount: ${colors.green(
ethers.formatUnits(amountToSend, 'ether')
)} ETH`
)
);
console.log(
colors.white(
` Gas Price: ${colors.green(
ethers.formatUnits(gasPrice, 'gwei')
)} Gwei`
)
);
await sleep(15000);
let receipt;
for (let retryCount = 0; retryCount < 5; retryCount++) {
try {
receipt = await provider.getTransactionReceipt(tx.hash);
if (receipt) {
if (receipt.status === 1) {
console.log(colors.green('Transaction Success!'));
console.log(
colors.green(` Block Number: ${receipt.blockNumber}`)
);
console.log(
colors.green(` Gas Used: ${receipt.gasUsed.toString()}`)
);
} else {
console.log(colors.red('Transaction FAILED'));
}
break;
} else {
console.log(
colors.yellow('Transaction is still pending. Retrying...')
);
await sleep(10000);
}
} catch (e) {
console.log(
colors.red(`Error checking transaction status: ${e.message}`)
);
await sleep(10000);
}
}
console.log();
}
console.log(
colors.green(`Finished transactions for address: ${senderAddress}`)
);
}
};
main();