| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- # -- coding: utf-8 --
- from web3 import Web3
- import random
- import time
- import os
- provider_url = "https://dream-rpc.somnia.network"
- w3 = Web3(Web3.HTTPProvider(provider_url))
- contract_data = [
- {
- "address": "0xF22eF0085f6511f70b01a68F360dCc56261F768a",
- "data_hash": "0xd0e30db0",
- "description": "SomniaExchangeTrade - 1"
- }
- ]
- file_path = os.path.join(os.path.dirname(__file__), 'AccountList.txt')
- def get_random_amount():
- random_tail = str(random.randint(1000, 9999))
- random_bit = random.randint(14, 18)
- random_balance = f"0.{random_tail.zfill(random_bit)}"
- return Web3.to_wei(random_balance, "ether")
- def get_random_contract_data():
- if not contract_data:
- print("The contract data array is empty, the contract cannot be selected, and the program exits.")
- exit(1)
- return random.choice(contract_data)
- def check_wallet_balance(balance, minimum_balance):
- if balance <= Web3.to_wei(minimum_balance, "ether"):
- print("The wallet balance is invalid.")
- exit(1)
- async def execute_contract(account, minimum_balance):
- try:
- contract_info = get_random_contract_data()
- address = contract_info["address"]
- data_hash = contract_info["data_hash"]
- description = contract_info["description"]
- print(f"Selected contract: {description}")
- print(f"Selected contract address: {address}")
- print(f"Selected contract dataHash: {data_hash}")
- balance = w3.eth.get_balance(account.address)
- before_balance = Web3.from_wei(balance, "ether")
- print(f"Native balance: {before_balance}")
- check_wallet_balance(balance, minimum_balance)
- amount_to_stake = get_random_amount()
- print(f"Amount to contract: {Web3.from_wei(amount_to_stake, 'ether')}")
- if balance < amount_to_stake:
- raise Exception("Insufficient balance for contract execution.")
- contract_address = Web3.to_checksum_address(address)
- abi = [
- {
- "inputs": [],
- "name": "deposit",
- "outputs": [],
- "stateMutability": "payable",
- "type": "function"
- }
- ]
- contract = w3.eth.contract(address=contract_address, abi=abi)
- nonce = w3.eth.get_transaction_count(account.address)
- now_gas = Web3.from_wei(w3.eth.gas_price, 'ether')
- print(f"Now Gas Fee is: {now_gas}")
- tx = contract.functions.deposit().build_transaction({
- "from": account.address,
- "value": amount_to_stake,
- "gas": 100000,
- "gasPrice": w3.eth.gas_price,
- "nonce": nonce,
- "chainId": w3.eth.chain_id
- })
- signed_tx = w3.eth.account.sign_transaction(tx, account.key)
- tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
- print(f"Contract Execution hash: {tx_hash.hex()}")
- receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
- execute_status = receipt["status"]
- if execute_status == 1:
- print("Contract Execution status: seccessful")
- elif execute_status == 0:
- print(f"Contract Execution status: failed\n{receipt}")
- else:
- print("Contract Execution status: unknown")
- balance_staking = w3.eth.get_balance(account.address)
- after_balance = Web3.from_wei(balance_staking, "ether")
- print(f"Native balance after transaction: {after_balance}")
- print(f"The cost of this transaction: {float(before_balance) - float(after_balance)}")
- except Exception as e:
- print(f"Error executing contract: {e}")
- async def run_multiple_staking(private_keys):
- last_times = 1
- min_delay = 10
- max_delay = 20
- minimum_balance = 0.2
- for private_key in private_keys:
- account = w3.eth.account.from_key(private_key.strip())
- print(f"Processing wallet with address: {account.address}")
- for i in range(last_times):
- if last_times > 1:
- print(f"Starting Contract attempt {i + 1}")
- await execute_contract(account, minimum_balance)
- print(f"Completed Contract attempt {i + 1}")
- if i < last_times - 1:
- delay = random.uniform(min_delay, max_delay)
- print(f"Waiting for {delay} seconds...")
- print('------------------------------------------------------------')
- time.sleep(random.uniform(min_delay, max_delay))
- async def main():
- try:
- with open(file_path, 'r') as file:
- private_keys = [line.strip() for line in file if line.strip()]
- await run_multiple_staking(private_keys)
- except Exception as err:
- print(f'读取文件时发生错误: {err}')
- exit(1)
- if __name__ == "__main__":
- import asyncio
- asyncio.run(main())
|