call_balance.py (667B)
1 # standard imports 2 import os 3 4 # external imports 5 from hexathon import strip_0x, add_0x 6 7 # local imports 8 from chainlib.eth.gas import balance, parse_balance 9 from chainlib.eth.connection import EthHTTPConnection 10 11 12 # create a random address to check 13 address_bytes = os.urandom(20) 14 address = add_0x(address_bytes.hex()) 15 16 # connect to rpc node and send request for balance 17 rpc_provider = os.environ.get('RPC_PROVIDER', 'http://localhost:8545') 18 rpc = EthHTTPConnection(rpc_provider) 19 o = balance(address) 20 print(o) 21 r = rpc.do(o) 22 23 clean_address = strip_0x(address) 24 clean_balance = parse_balance(r) 25 26 print('address {} has balance {}'.format(clean_address, clean_balance))