# -*- coding: utf-8 -*- import time import random from web3 import Web3 from eth_account import Account private_key_list = [ "48cd0f0db84c9ca488292c9da449236d14a845e07618b6c0975cb158ccd60794" ] def claim_token(private_key): # 配置信息 rpc_url = "https://rpc.sepolia.ethpandaops.io" target_chain_id = 11155111 contract_address = "0x3edf60dd017ace33a0220f78741b5581c385a1ba" try: # 连接Web3 web3 = Web3(Web3.HTTPProvider(rpc_url)) if not web3.is_connected(): print("❌ 无法连接到目标网络") return False # 校验链ID是否为Sepolia chain_id = web3.eth.chain_id if chain_id != target_chain_id: print(f"❌ 连接了错误的网络,当前链ID: {chain_id}, 期望: {target_chain_id}") return False # 创建账户对象 account = Account.from_key("0x" + private_key) # 查询当前账户余额 balance = web3.eth.get_balance(account.address) balance_eth = web3.from_wei(balance, 'ether') print(f"当前账户余额: {balance_eth} Token") # 构造调用数据 wallet_address = account.address[2:].lower() # 去掉0x前缀 wallet_param = wallet_address.zfill(64) # 补足64位(32字节) call_data = "0x6a627842" + wallet_param # 构造交易 transaction = { "to": Web3.to_checksum_address(contract_address), "value": 0, "gas": 100000, # 固定Gas限制,可根据需要调整 "gasPrice": web3.to_wei(20, "gwei"), # 固定Gas价格,可调整 "nonce": web3.eth.get_transaction_count(account.address), "data": call_data, "chainId": target_chain_id, } print(f"📋 调用数据: {call_data}") print("📤 发送交易中...") # 签名交易 signed_txn = web3.eth.account.sign_transaction( transaction, private_key) # 发送交易 tx_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction) tx_hash_hex = tx_hash.hex() print(f"📤 交易已发送: {tx_hash_hex}") print("⏳ 等待交易确认...") # 等待交易确认 receipt = web3.eth.wait_for_transaction_receipt(tx_hash, timeout=300) if receipt.status == 1: print(f"✅ 代币领取成功! Gas使用: {receipt.gasUsed}") print(f"🔗 交易链接: https://sepolia.etherscan.io/tx/{tx_hash_hex}") return True else: print("❌ 交易执行失败") return False except Exception as e: error_msg = str(e).lower() if "insufficient funds" in error_msg: print("❌ ETH余额不足,无法支付Gas费用") elif "nonce too low" in error_msg: print("❌ Nonce值过低,请稍后重试") elif "replacement transaction underpriced" in error_msg: print("❌ 交易费用过低,请提高Gas价格") else: print(f"❌ 领取失败: {e}") return False if __name__ == "__main__": claim_times = 200000 for private_key in private_key_list: for i in range(claim_times): print(f'开始领取第 {i+1} 次') n = 1 retry_min_time = 10 retry_max_time = 20 retry_time = random.uniform(retry_min_time, retry_max_time) retry_max_times = 3 while True: if n > retry_max_times: print(f'领取 {i+1} 次失败, 重试次数超过 {retry_max_times} 次, 跳过') break if claim_token(private_key): break print(f'领取 {i+1} 次失败, 重试第 {n} 次, 等待 {retry_time} 秒后再次领取') n += 1 time.sleep(retry_time) print(f'领取第 {i+1} 次成功, 等待 {retry_time} 秒后再次领取') time.sleep(retry_time)