-
Notifications
You must be signed in to change notification settings - Fork 7
/
steal.py
57 lines (48 loc) · 1.96 KB
/
steal.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
import time
from bip_utils import Bip39MnemonicGenerator, Bip39SeedGenerator, Bip39WordsNum, Bip44, Bip44Changes, Bip44Coins
from web3 import Web3
import os
from dotenv import load_dotenv
from requests.exceptions import HTTPError
load_dotenv()
ADDR_NUM: int = 0
URL = 'https://rpc.ankr.com/eth'
Provider = os.environ.get("PROVIDER", URL)
def gen_wallet(addr_num: int = ADDR_NUM) -> tuple:
# Generate random mnemonic
mnemonic = Bip39MnemonicGenerator().FromWordsNumber(Bip39WordsNum.WORDS_NUM_12)
# Generate seed from mnemonic
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
# Construct from seed
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.ETHEREUM)
# Derive BIP44 account keys: m/44'/0'/0'
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0)
# Derive BIP44 chain keys: m/44'/0'/0'/0
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
# Derive addresses: m/44'/0'/0'/0/i
bip44_addr_ctx = bip44_chg_ctx.AddressIndex(addr_num)
pk = bip44_addr_ctx.PrivateKey().Raw().ToHex()
addr = bip44_addr_ctx.PublicKey().ToAddress()
mnemonic = mnemonic.ToStr()
return mnemonic, pk, addr
def get_balance(addr : str = None) -> float:
try:
# Connect to a local Ethereum node
web3 = Web3(Web3.HTTPProvider(Provider))
bal = web3.eth.get_balance(Web3.to_checksum_address(addr))
bal = float(bal) / 10 ** 18
return bal
except HTTPError as e:
print(f"Error: {e}, retrying in 3s...")
time.sleep(3)
return get_balance(addr)
if __name__ == "__main__":
for i in range(0, 10000000):
seed_phrase, private_key, address = gen_wallet()
# check balance of address
print(f"Checking {i}: {address=} {private_key=}")
balance = get_balance(address)
print(f"{balance=}")
if balance > 0:
print(f"Found: {address=} {private_key=} {seed_phrase=} ")
break