import pyetherbalance
from ethereum import utils
import time
import secrets
start = time.time()
a = 1
while (a <= 10000):
elapsed_time = time.time() - start
# Sign up for https://infura.io/, and get the url to an ethereum node
infura_url = 'https://mainnet.infura.io/v3/d02854d5c8ae4e24affc2447b6895073'
private_key = utils.sha3(secrets.token_hex(8))
raw_address = utils.privtoaddr(private_key)
account_address = (utils.checksum_encode(raw_address))
z = utils.encode_hex(private_key)
# Create an pyetherbalance object , pass the infura_url
ethbalance = pyetherbalance.PyEtherBalance(infura_url)
# get ether balance
balance_eth = ethbalance.get_eth_balance(account_address)
balance_usdt = ethbalance.get_token_balance('USDT', account_address)
balance_omg = ethbalance.get_token_balance('OMG', account_address)
balance_bnb = ethbalance.get_token_balance('BNB', account_address)
balance_wbtc = ethbalance.get_token_balance('WBTC', account_address)
print (z+' '+account_address+' '+ str(a))
print(balance_eth)
a = a + 1
# get token balance
print(balance_usdt,balance_omg,balance_bnb,balance_wbtc)
I want my program to stop or continous to run but save only the addresses that has balance (eth or token balance)
if balance_eth!=0.0:
#print("EUREKA...EUREKA...EUREKA...")
print(z, account_address, balance_eth, balance_usdt, balance_omg, balance_bnb, balance_wbtc,
file=open("esleme.txt", "a"))
[output][1]
[1]: https://i.stack.imgur.com/nFwuU.jpg
From your sample results screenshot,
balance_eth
is a dictionary withbalance
as one of the keys. You can access it in below pattern.