-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestnet_ethsener.py
101 lines (80 loc) · 4.17 KB
/
testnet_ethsener.py
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
from web3 import Web3
# Подключение к сети Arbitrum Sepolia
ARBITRUM_SEPOLIA_RPC = "https://sepolia-rollup.arbitrum.io/rpc" # Тестовый RPC для Arbitrum Sepolia
web3 = Web3(Web3.HTTPProvider(ARBITRUM_SEPOLIA_RPC))
if not web3.is_connected():
raise ConnectionError("Не удалось подключиться к RPC сети Arbitrum Sepolia.")
# Проверка текущего Chain ID
current_chain_id = web3.eth.chain_id
print(f"Chain ID текущего RPC: {current_chain_id}")
# Приватный ключ отправителя
private_key = "ВАШ_ПРИВАТНЫЙ_КЛЮЧ" # Укажите ваш приватный ключ
# Извлекаем адрес отправителя из приватного ключа
sender_account = web3.eth.account.from_key(private_key)
sender_address = sender_account.address
print(f"Адрес отправителя: {sender_address}")
# Список получателей и сумм в ETH
recipients = [
"0xRecipientAddress1",
"0xRecipientAddress2",
"0xRecipientAddress3",
]
amounts_in_eth = [
0.1, # ETH для первого адреса
0.2, # ETH для второго адреса
0.3, # ETH для третьего адреса
]
# Проверка, что длина списков совпадает
if len(recipients) != len(amounts_in_eth):
raise ValueError("Длина списков recipients и amounts_in_eth должна совпадать")
# Конвертируем суммы из ETH в Wei
amounts_in_wei = [Web3.to_wei(amount, "ether") for amount in amounts_in_eth]
# Создаем транзакции
nonce = web3.eth.get_transaction_count(sender_address)
# Получаем текущую базовую комиссию
block = web3.eth.get_block('latest')
base_fee = block.get('baseFeePerGas', 0)
# Устанавливаем комиссии
max_priority_fee = Web3.to_wei(2, 'gwei') # Приоритетная комиссия
max_fee = base_fee + max_priority_fee # Максимальная комиссия
# Подсчет общей суммы перевода
total_amount_in_wei = sum(amounts_in_wei)
# Проверяем, достаточно ли ETH на балансе
balance = web3.eth.get_balance(sender_address)
required_gas = max_fee * 21000 * len(recipients) # Общая комиссия
if balance < total_amount_in_wei + required_gas:
raise ValueError("Недостаточно ETH для перевода и покрытия комиссии")
# Инициализируем счетчики для общей комиссии
total_gas_used = 0
# Отправка средств
for i, recipient in enumerate(recipients):
tx = {
'nonce': nonce + i,
'to': recipient,
'value': amounts_in_wei[i],
'gas': 21000,
'maxFeePerGas': max_fee,
'maxPriorityFeePerGas': max_priority_fee,
'chainId': current_chain_id, # Используем Chain ID, полученный из RPC
}
# Подписываем транзакцию
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
# Отправляем транзакцию
tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
print(f"Транзакция {i + 1} отправлена: {web3.to_hex(tx_hash)}")
# Увеличиваем общий объем газа
total_gas_used += 21000
# Получение остатка баланса после отправки транзакций
remaining_balance = web3.eth.get_balance(sender_address)
remaining_balance_in_eth = Web3.from_wei(remaining_balance, "ether")
# Расчет итогов
total_sent_in_eth = Web3.from_wei(total_amount_in_wei, "ether")
total_fee_in_wei = total_gas_used * max_fee
total_fee_in_eth = Web3.from_wei(total_fee_in_wei, "ether")
# Вывод результатов
print(f"\n--- Результаты ---")
print(f"Всего отправлено: {total_sent_in_eth} ETH")
print(f"Потрачено на комиссию: {total_fee_in_eth} ETH")
print(f"Остаток на кошельке: {remaining_balance_in_eth} ETH")
print("------------------")
print("Все транзакции успешно отправлены!")