forked from dante4rt/t3rn-airdrop-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
147 lines (127 loc) · 4.33 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
146
147
require('colors');
const { Wallet, JsonRpcProvider, ethers, parseUnits } = require('ethers');
const fs = require('fs');
const readlineSync = require('readline-sync');
const moment = require('moment');
const T3RN_ABI = require('./contracts/ABI');
const { displayHeader } = require('./utils/display');
const { transactionData, delay } = require('./utils/helper');
const { getAmount } = require('./utils/api');
const PRIVATE_KEYS = JSON.parse(fs.readFileSync('privateKeys.json', 'utf-8'));
const RPC_URL = T3RN_ABI.at(-1).RPC_ARBT;
const provider = new JsonRpcProvider(RPC_URL);
const CONTRACT_ADDRESS = T3RN_ABI.at(-1).CA_ARBT;
(async () => {
displayHeader();
console.log('⏳ Please wait...'.yellow);
console.log('');
const options = readlineSync.question(
'Choose the network that you want to use 👇\n1. Arbitrum Sepolia to Base Sepolia\n2. Arbitrum Sepolia to Blast Sepolia\n3. Arbitrum Sepolia to Optimism Sepolia\n4. Exit\n\nEnter 1, 2, 3, or 4: '
);
if (options === '4' || !options) {
console.log('👋 Exiting the bot. See you next time!'.cyan);
console.log('Subscribe: https://t.me/HappyCuanAirdrop.'.green);
process.exit(0);
}
const numTx = readlineSync.questionInt(
'🔄 How many times you want to swap or bridge? '
);
if (numTx <= 0) {
console.log('❌ Number of transactions must be greater than 0!'.red);
process.exit(1);
}
for (const PRIVATE_KEY of PRIVATE_KEYS) {
const wallet = new Wallet(PRIVATE_KEY, provider);
let totalSuccess = 0;
while (totalSuccess < numTx) {
try {
const balance = await provider.getBalance(wallet.address);
const balanceInEth = ethers.formatUnits(balance, 'ether');
console.log(
`⚙️ [ ${moment().format(
'HH:mm:ss'
)} ] Doing transactions for address ${wallet.address}...`.yellow
);
if (balanceInEth < 0.001) {
console.log(
`❌ [ ${moment().format(
'HH:mm:ss'
)} ] Your balance is too low (💰 ${balanceInEth} ETH), please claim faucet first!`
.red
);
process.exit(0);
}
let counter = numTx - totalSuccess;
while (counter > 0) {
try {
const amount = await getAmount(options);
if (!amount) {
console.log(
`❌ Failed to get the amount. Skipping transaction...`.red
);
continue;
}
const request = transactionData(
wallet.address,
amount.hex,
options
);
const gasPrice = parseUnits('0.1', 'gwei'); // adjustable
const transaction = {
data: request,
to: CONTRACT_ADDRESS,
gasLimit: 2000000, // adjustable
gasPrice,
from: wallet.address,
value: parseUnits('0.0001', 'ether'), // adjustable
};
const result = await wallet.sendTransaction(transaction);
console.log(
`✅ [ ${moment().format(
'HH:mm:ss'
)} ] Transaction successful from Arbitrum Sepolia to ${
options === '1' ? 'Base' : options === '2' ? 'Blast' : 'OP'
} Sepolia!`.green
);
console.log(
`🔗 [ ${moment().format(
'HH:mm:ss'
)} ] Transaction hash: https://sepolia-explorer.arbitrum.io/tx/${
result.hash
}`.green
);
console.log('');
totalSuccess++;
counter--;
if (counter > 0) {
await delay(30000);
}
} catch (error) {
console.log(
`❌ [ ${moment().format(
'HH:mm:ss'
)} ] Error during transaction: ${error}`.red
);
}
}
} catch (error) {
console.log(
`❌ [ ${moment().format(
'HH:mm:ss'
)} ] Error in processing transactions: ${error}`.red
);
}
}
}
console.log('');
console.log(
`🎉 [ ${moment().format(
'HH:mm:ss'
)} ] All ${numTx} transactions are complete!`.green
);
console.log(
`📢 [ ${moment().format(
'HH:mm:ss'
)} ] Subscribe: https://t.me/HappyCuanAirdrop`.green
);
})();