-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
526 lines (454 loc) · 23.1 KB
/
Copy pathbot.py
File metadata and controls
526 lines (454 loc) · 23.1 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
from web3 import Web3
from web3.exceptions import TransactionNotFound
from eth_account import Account
from aiohttp import ClientSession, ClientTimeout, ClientResponseError, BasicAuth
from aiohttp_socks import ProxyConnector
from datetime import datetime
from colorama import *
import asyncio, random, json, re, os, pytz
wib = pytz.timezone('Asia/Jakarta')
class Turnkey:
def __init__(self) -> None:
self.RPC_URL = "https://eth-sepolia.g.alchemy.com/v2/KatanYBT5TYSiPJ8Lr8iE_-kebTVnVvq"
self.RECEIVER = "0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7"
self.ERC20_CONTRACT_ABI = json.loads('''[
{"type":"function","name":"balanceOf","stateMutability":"view","inputs":[{"name":"address","type":"address"}],"outputs":[{"name":"","type":"uint256"}]}
]''')
self.proxies = []
self.proxy_index = 0
self.account_proxies = {}
self.used_nonce = {}
self.tx_count = 0
self.min_amount = 0
self.max_amount = 0
self.min_delay = 0
self.max_delay = 0
def clear_terminal(self):
os.system('cls' if os.name == 'nt' else 'clear')
def log(self, message):
print(
f"{Fore.CYAN + Style.BRIGHT}[ {datetime.now().astimezone(wib).strftime('%x %X %Z')} ]{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} | {Style.RESET_ALL}{message}",
flush=True
)
def welcome(self):
print(Fore.LIGHTGREEN_EX + Style.BRIGHT + "\n" + "═" * 60)
print(Fore.GREEN + Style.BRIGHT + " ⚡Turnkey Automation BOT ⚡")
print(Fore.CYAN + Style.BRIGHT + " ────────────────────────────────")
print(Fore.YELLOW + Style.BRIGHT + " 🧠 Project : Turnkey - Automation Bot")
print(Fore.YELLOW + Style.BRIGHT + " 🧑💻 Author : YetiDAO")
print(Fore.YELLOW + Style.BRIGHT + " 🌐 Status : Running & Monitering...")
print(Fore.CYAN + Style.BRIGHT + " ────────────────────────────────")
print(Fore.MAGENTA + Style.BRIGHT + " 🧬 Powered by Cryptodai3 × YetiDAO | Buddy v1.0 🚀")
print(Fore.LIGHTGREEN_EX + Style.BRIGHT + "═" * 60 + "\n")
def format_seconds(self, seconds):
hours, remainder = divmod(seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"
async def load_proxies(self, use_proxy_choice: bool):
filename = "proxy.txt"
try:
if use_proxy_choice == 1:
async with ClientSession(timeout=ClientTimeout(total=30)) as session:
async with session.get("https://raw.githubusercontent.com/monosans/proxy-list/refs/heads/main/proxies/http.txt") as response:
response.raise_for_status()
content = await response.text()
with open(filename, 'w') as f:
f.write(content)
self.proxies = [line.strip() for line in content.splitlines() if line.strip()]
else:
if not os.path.exists(filename):
self.log(f"{Fore.RED + Style.BRIGHT}File {filename} Not Found.{Style.RESET_ALL}")
return
with open(filename, 'r') as f:
self.proxies = [line.strip() for line in f.read().splitlines() if line.strip()]
if not self.proxies:
self.log(f"{Fore.RED + Style.BRIGHT}No Proxies Found.{Style.RESET_ALL}")
return
self.log(
f"{Fore.GREEN + Style.BRIGHT}Proxies Total : {Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT}{len(self.proxies)}{Style.RESET_ALL}"
)
except Exception as e:
self.log(f"{Fore.RED + Style.BRIGHT}Failed To Load Proxies: {e}{Style.RESET_ALL}")
self.proxies = []
def check_proxy_schemes(self, proxies):
schemes = ["http://", "https://", "socks4://", "socks5://"]
if any(proxies.startswith(scheme) for scheme in schemes):
return proxies
return f"http://{proxies}"
def get_next_proxy_for_account(self, token):
if token not in self.account_proxies:
if not self.proxies:
return None
proxy = self.check_proxy_schemes(self.proxies[self.proxy_index])
self.account_proxies[token] = proxy
self.proxy_index = (self.proxy_index + 1) % len(self.proxies)
return self.account_proxies[token]
def rotate_proxy_for_account(self, token):
if not self.proxies:
return None
proxy = self.check_proxy_schemes(self.proxies[self.proxy_index])
self.account_proxies[token] = proxy
self.proxy_index = (self.proxy_index + 1) % len(self.proxies)
return proxy
def build_proxy_config(self, proxy=None):
if not proxy:
return None, None, None
if proxy.startswith("socks"):
connector = ProxyConnector.from_url(proxy)
return connector, None, None
elif proxy.startswith("http"):
match = re.match(r"http://(.*?):(.*?)@(.*)", proxy)
if match:
username, password, host_port = match.groups()
clean_url = f"http://{host_port}"
auth = BasicAuth(username, password)
return None, clean_url, auth
else:
return None, proxy, None
raise Exception("Unsupported Proxy Type.")
def generate_address(self, account: str):
try:
account = Account.from_key(account)
address = account.address
return address
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT}Status:{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} Generate Address Failed {Style.RESET_ALL}"
f"{Fore.MAGENTA+Style.BRIGHT}-{Style.RESET_ALL}"
f"{Fore.YELLOW+Style.BRIGHT} {str(e)} {Style.RESET_ALL} "
)
return None
def mask_account(self, account):
try:
mask_account = account[:6] + '*' * 6 + account[-6:]
return mask_account
except Exception as e:
return None
async def get_web3_with_check(self, address: str, use_proxy: bool, retries=3, timeout=60):
request_kwargs = {"timeout": timeout}
proxy = self.get_next_proxy_for_account(address) if use_proxy else None
if use_proxy and proxy:
request_kwargs["proxies"] = {"http": proxy, "https": proxy}
for attempt in range(retries):
try:
web3 = Web3(Web3.HTTPProvider(self.RPC_URL, request_kwargs=request_kwargs))
web3.eth.get_block_number()
return web3
except Exception as e:
if attempt < retries - 1:
await asyncio.sleep(3)
continue
raise Exception(f"Failed to Connect to RPC: {str(e)}")
async def get_token_balance(self, address: str, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
balance = web3.eth.get_balance(address)
token_balance = balance / (10 ** 18)
return token_balance
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None
async def send_raw_transaction_with_retries(self, account, web3, tx, retries=5):
for attempt in range(retries):
try:
signed_tx = web3.eth.account.sign_transaction(tx, account)
raw_tx = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_hash = web3.to_hex(raw_tx)
return tx_hash
except TransactionNotFound:
pass
except Exception as e:
pass
await asyncio.sleep(2 ** attempt)
raise Exception("Transaction Hash Not Found After Maximum Retries")
async def wait_for_receipt_with_retries(self, web3, tx_hash, retries=5):
for attempt in range(retries):
try:
receipt = await asyncio.to_thread(web3.eth.wait_for_transaction_receipt, tx_hash, timeout=300)
return receipt
except TransactionNotFound:
pass
except Exception as e:
pass
await asyncio.sleep(2 ** attempt)
raise Exception("Transaction Receipt Not Found After Maximum Retries")
async def perform_transfer(self, account: str, address: str, tx_amount: float, use_proxy: bool):
try:
web3 = await self.get_web3_with_check(address, use_proxy)
amount_to_wei = web3.to_wei(tx_amount, "ether")
tx = {
"to": self.RECEIVER,
"value": amount_to_wei,
"gas": 21000,
"maxFeePerGas": web3.to_wei(0.002, "gwei"),
"maxPriorityFeePerGas": web3.to_wei(0.001, "gwei"),
"nonce": self.used_nonce[address],
"chainId": web3.eth.chain_id
}
tx_hash = await self.send_raw_transaction_with_retries(account, web3, tx)
receipt = await self.wait_for_receipt_with_retries(web3, tx_hash)
block_number = receipt.blockNumber
self.used_nonce[address] += 1
return tx_hash, block_number
except Exception as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Message :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None, None
async def print_timer(self):
for remaining in range(random.randint(self.min_delay, self.max_delay), 0, -1):
print(
f"{Fore.CYAN + Style.BRIGHT}[ {datetime.now().astimezone(wib).strftime('%x %X %Z')} ]{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} | {Style.RESET_ALL}"
f"{Fore.BLUE + Style.BRIGHT}Wait For{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} {remaining} {Style.RESET_ALL}"
f"{Fore.BLUE + Style.BRIGHT}Seconds For Next Tx...{Style.RESET_ALL}",
end="\r",
flush=True
)
await asyncio.sleep(1)
def print_question(self):
while True:
try:
tx_count = int(input(f"{Fore.YELLOW + Style.BRIGHT}Tx Count For Each Wallet -> {Style.RESET_ALL}").strip())
if tx_count > 0:
self.tx_count = tx_count
break
else:
print(f"{Fore.RED + Style.BRIGHT}Tx Count must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
while True:
try:
min_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter Min Tx Amount ( ETH Sepolia ) [1 or 0.01 or 0.001, etc in decimals] -> {Style.RESET_ALL}").strip())
if min_amount > 0:
self.min_amount = min_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}Amount must be > 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
max_amount = float(input(f"{Fore.YELLOW + Style.BRIGHT}Enter Max TX Amount ( ETH Sepolia ) [1 or 0.01 or 0.001, etc in decimals] -> {Style.RESET_ALL}").strip())
if max_amount >= min_amount:
self.max_amount = max_amount
break
else:
print(f"{Fore.RED + Style.BRIGHT}Amount must be >= min tx amount.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a float or decimal number.{Style.RESET_ALL}")
while True:
try:
min_delay = int(input(f"{Fore.YELLOW + Style.BRIGHT}Min Delay For Each Tx -> {Style.RESET_ALL}").strip())
if min_delay >= 0:
self.min_delay = min_delay
break
else:
print(f"{Fore.RED + Style.BRIGHT}Min Delay must be >= 0.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
while True:
try:
max_delay = int(input(f"{Fore.YELLOW + Style.BRIGHT}Max Delay For Each Tx -> {Style.RESET_ALL}").strip())
if max_delay >= min_delay:
self.max_delay = max_delay
break
else:
print(f"{Fore.RED + Style.BRIGHT}Max Delay must be >= Min Delay.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number.{Style.RESET_ALL}")
while True:
try:
print(f"{Fore.WHITE + Style.BRIGHT}1. Run With Free Proxyscrape Proxy{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}2. Run With Private Proxy{Style.RESET_ALL}")
print(f"{Fore.WHITE + Style.BRIGHT}3. Run Without Proxy{Style.RESET_ALL}")
choose = int(input(f"{Fore.BLUE + Style.BRIGHT}Choose [1/2/3] -> {Style.RESET_ALL}").strip())
if choose in [1, 2, 3]:
proxy_type = (
"With Free Proxyscrape" if choose == 1 else
"With Private" if choose == 2 else
"Without"
)
print(f"{Fore.GREEN + Style.BRIGHT}Run {proxy_type} Proxy Selected.{Style.RESET_ALL}")
break
else:
print(f"{Fore.RED + Style.BRIGHT}Please enter either 1, 2 or 3.{Style.RESET_ALL}")
except ValueError:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter a number (1, 2 or 3).{Style.RESET_ALL}")
rotate = False
if choose in [1, 2]:
while True:
rotate = input(f"{Fore.BLUE + Style.BRIGHT}Rotate Invalid Proxy? [y/n] -> {Style.RESET_ALL}").strip()
if rotate in ["y", "n"]:
rotate = rotate == "y"
break
else:
print(f"{Fore.RED + Style.BRIGHT}Invalid input. Enter 'y' or 'n'.{Style.RESET_ALL}")
return choose, rotate
async def check_connection(self, proxy_url=None):
connector, proxy, proxy_auth = self.build_proxy_config(proxy_url)
try:
async with ClientSession(connector=connector, timeout=ClientTimeout(total=10)) as session:
async with session.get(url="https://api.ipify.org?format=json", proxy=proxy, proxy_auth=proxy_auth) as response:
response.raise_for_status()
return True
except (Exception, ClientResponseError) as e:
self.log(
f"{Fore.CYAN+Style.BRIGHT}Status:{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} Connection Not 200 OK {Style.RESET_ALL}"
f"{Fore.MAGENTA+Style.BRIGHT}-{Style.RESET_ALL}"
f"{Fore.YELLOW+Style.BRIGHT} {str(e)} {Style.RESET_ALL}"
)
return None
async def process_check_connection(self, address: int, use_proxy: bool, rotate_proxy: bool):
while True:
proxy = self.get_next_proxy_for_account(address) if use_proxy else None
self.log(
f"{Fore.CYAN + Style.BRIGHT}Proxy :{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} {proxy} {Style.RESET_ALL}"
)
is_valid = await self.check_connection(proxy)
if not is_valid:
if rotate_proxy:
proxy = self.rotate_proxy_for_account(address)
continue
return False
return True
async def process_perform_transfer(self, account: str, address: str, tx_amount: float, use_proxy: bool):
tx_hash, block_number = await self.perform_transfer(account, address, tx_amount, use_proxy)
if tx_hash and block_number:
explorer = f"https://sepolia.etherscan.io/tx/{tx_hash}"
self.log(
f"{Fore.CYAN+Style.BRIGHT} Status :{Style.RESET_ALL}"
f"{Fore.GREEN+Style.BRIGHT} Success {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Block :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {block_number} {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Tx Hash :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {tx_hash} {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Explorer:{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {explorer} {Style.RESET_ALL}"
)
else:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Status :{Style.RESET_ALL}"
f"{Fore.RED+Style.BRIGHT} Perform On-Chain Failed {Style.RESET_ALL}"
)
async def process_accounts(self, account: str, address: str, use_proxy: bool, rotate_proxy: bool):
is_valid = await self.process_check_connection(address, use_proxy, rotate_proxy)
if is_valid:
web3 = await self.get_web3_with_check(address, use_proxy)
if not web3:
self.log(
f"{Fore.CYAN + Style.BRIGHT}Status:{Style.RESET_ALL}"
f"{Fore.RED + Style.BRIGHT} Web3 Not Connected {Style.RESET_ALL}"
)
return
self.used_nonce[address] = web3.eth.get_transaction_count(address, "pending")
for i in range(self.tx_count):
self.log(
f"{Fore.MAGENTA+Style.BRIGHT} ● {Style.RESET_ALL}"
f"{Fore.GREEN+Style.BRIGHT}Transfer{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {i+1} {Style.RESET_ALL}"
f"{Fore.MAGENTA+Style.BRIGHT}Of{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {self.tx_count} {Style.RESET_ALL} "
)
balance = await self.get_token_balance(address, use_proxy)
tx_amount = round(random.uniform(self.min_amount, self.max_amount), 7)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Balance :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {balance} ETH Sepolia {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Amount :{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {tx_amount} ETH Sepolia {Style.RESET_ALL}"
)
self.log(
f"{Fore.CYAN+Style.BRIGHT} Receiver:{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {self.RECEIVER} {Style.RESET_ALL}"
)
if not balance or balance <= tx_amount:
self.log(
f"{Fore.CYAN+Style.BRIGHT} Status :{Style.RESET_ALL}"
f"{Fore.YELLOW+Style.BRIGHT} Insufficient ETH Sepolia Token Balance {Style.RESET_ALL}"
)
return
await self.process_perform_transfer(account, address, tx_amount, use_proxy)
await self.print_timer()
async def main(self):
try:
with open('accounts.txt', 'r') as file:
accounts = [line.strip() for line in file if line.strip()]
use_proxy_choice, rotate_proxy = self.print_question()
use_proxy = False
if use_proxy_choice in [1, 2]:
use_proxy = True
while True:
self.clear_terminal()
self.welcome()
self.log(
f"{Fore.GREEN + Style.BRIGHT}Account's Total: {Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT}{len(accounts)}{Style.RESET_ALL}"
)
if use_proxy:
await self.load_proxies(use_proxy_choice)
separator = "=" * 25
for account in accounts:
if account:
address = self.generate_address(account)
self.log(
f"{Fore.CYAN + Style.BRIGHT}{separator}[{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} {self.mask_account(address)} {Style.RESET_ALL}"
f"{Fore.CYAN + Style.BRIGHT}]{separator}{Style.RESET_ALL}"
)
if not address:
self.log(
f"{Fore.CYAN + Style.BRIGHT}Status:{Style.RESET_ALL}"
f"{Fore.RED + Style.BRIGHT} Invalid Private Key or Library Version Not Supported {Style.RESET_ALL}"
)
continue
await self.process_accounts(account, address, use_proxy, rotate_proxy)
await asyncio.sleep(3)
self.log(f"{Fore.CYAN + Style.BRIGHT}={Style.RESET_ALL}"*72)
seconds = 24 * 60 * 60
while seconds > 0:
formatted_time = self.format_seconds(seconds)
print(
f"{Fore.CYAN+Style.BRIGHT}[ Wait for{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} {formatted_time} {Style.RESET_ALL}"
f"{Fore.CYAN+Style.BRIGHT}... ]{Style.RESET_ALL}"
f"{Fore.WHITE+Style.BRIGHT} | {Style.RESET_ALL}"
f"{Fore.BLUE+Style.BRIGHT}All Accounts Have Been Processed.{Style.RESET_ALL}",
end="\r"
)
await asyncio.sleep(1)
seconds -= 1
except FileNotFoundError:
self.log(f"{Fore.RED}File 'accounts.txt' Not Found.{Style.RESET_ALL}")
return
except Exception as e:
self.log(f"{Fore.RED+Style.BRIGHT}Error: {e}{Style.RESET_ALL}")
raise e
if __name__ == "__main__":
try:
bot = Turnkey()
asyncio.run(bot.main())
except KeyboardInterrupt:
print(
f"{Fore.CYAN + Style.BRIGHT}[ {datetime.now().astimezone(wib).strftime('%x %X %Z')} ]{Style.RESET_ALL}"
f"{Fore.WHITE + Style.BRIGHT} | {Style.RESET_ALL}"
f"{Fore.RED + Style.BRIGHT}[ EXIT ] Turnkey - BOT{Style.RESET_ALL} "
)