def get_balance(wallet_type, address, contract_address=None, api_key=None): """Get the balance of a single wallet.""" value = 0 if wallet_type == 'ETH': account = Account(address=address, api_key=api_key) value += float(account.get_balance()) / 1000000000000000000 elif wallet_type == 'EOS': api = Tokens(contract_address=contract_address, api_key=api_key) value += float(api.get_token_balance(address=address)) / 1000000000000000000 elif wallet_type == 'XRB': # hardcoded for now... value = 10.179600 else: value += blockcypher.get_total_balance(address, coin_symbol=wallet_type.lower()) / 100000000 return value
def main(): if len(sys.argv) < 2: print("usage: " + os.path.basename(__file__) + " user_wallet") print("Finds the ether balance of a wallet address.") sys.exit(1) else: wallet_addy = str(sys.argv[1]) address = wallet_addy api = Account(address=wallet_addy, api_key=key) balance = api.get_balance() balance = int(balance) if (balance > 0): balance = balance / 1000000000000000000 print(balance)
def test_get_balance(self): api = Account(address=SINGLE_ACCOUNT, api_key=API_KEY) self.assertEqual(api.get_balance(), SINGLE_BALANCE)
def test_get_balance(self): api = Account(address=SINGLE_ACCOUNT, api_key=API_KEY) self.assertEqual(api.get_balance(), SINGLE_BALANCE)
from etherscan.tokens import Tokens from etherscan.transactions import Transactions import os import json # Get API Key path = os.getcwd() with open(os.path.join(path, 'api_key.json'), mode='r') as key_file: key = json.loads(key_file.read())['key'] # Accounts address = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e' api = Account(address=address, api_key=key) balance = api.get_balance() transaction = api.get_transaction_page(page=1, offset=10000, sort='des') # erc20 = True) transactions = api.get_all_transactions(offset=10000, sort='asc', internal=False) block = api.get_blocks_mined_page(page=1, offset=1, blocktype='blocks') blocks = api.get_all_blocks_mined(offset=10, blocktype='uncles') # address = ['0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', # '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'] # #api = Account(address=address, api_key=key) #balances = api.get_balance_multiple() # print(balances)
class Accounts(EtherscanAPI): def __init__(self, address): super().__init__() self.address = address self.api = Account(address=address, api_key=self.key) self._create_data_folder(DATA_DIR) def _data_to_df_save(self, data, filename, save=False): df = pd.DataFrame(data) df['timeStamp'] = pd.to_datetime(df['timeStamp'], unit='s') df.set_index('timeStamp', inplace=True) if save: filepath = os.path.join(DATA_DIR, filename) df.to_csv(filepath) print('Data file saved') return df def get_balance(self): balance = self.api.get_balance() return balance def get_balance_multi(self): balances = self.api.get_balance_multiple() return balances def get_block_mined(self, page=1, offset=10000, blocktype='blocks', save=False): block = self.api.get_blocks_mined_page(page=page, offset=offset, blocktype=blocktype) filename = f'{self.address}-page{page}-offset{offset}-blocks-mined.csv' blocks_df = self._data_to_df_save(block, filename, save=save) return blocks_df def get_all_blocks_mined(self, offset=10000, blocktype='blocks', save=False): blocks = self.api.get_all_blocks_mined(offset=offset, blocktype=blocktype) filename = f'{self.address}-all-blocks-mined.csv' blocks_df = self._data_to_df_save(blocks, filename, save=save) return blocks_df def get_all_transactions(self, offset=1000, sort='acs', internal=False, save=False): transactions = self.api.get_all_transactions(offset=offset, sort=sort, internal=internal) filename = f'{self.address}-all-transactions.csv' transac_df = self._data_to_df_save(transactions, filename, save=save) return transac_df def get_transaction_page(self, page=1, offset=10000, sort='asc', internal=False, erc20=False, save=True): transactions = self.api.get_transaction_page(page=page, offset=offset, sort=sort, internal=internal, erc20=erc20) transac_df = pd.DataFrame(transactions) transac_df['timeStamp'] = pd.to_datetime(transac_df['timeStamp'], unit='s') transac_df.set_index('timeStamp', inplace=True) filename = f'{self.address}-page{page}-offset{offset}-transactions.csv' transac_df = self._data_to_df_save(transactions, filename, save=save) return transac_df
def get_balance(address): api = Account(address=address, api_key=key) balance = api.get_balance() print(balance)
from etherscan.accounts import Account import json with open('../../api_key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] address = '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a' api = Account(address=address, api_key=key) balance = api.get_balance() print(balance)
def walletBalance(walletAddress): api_key = 'IVPR3T2CWJ2TKUYH6824HNGKKJ4ENEM9EU' api = Account(address=walletAddress, api_key=api_key) balance = api.get_balance() return balance
from etherscan.stats import Stats from etherscan.tokens import Tokens from etherscan.transactions import Transactions import pandas as pd import json with open('./api_key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] # Accounts ## Single address address = '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b' api = Account(address=address, api_key=key) ### get balance single_bal = api.get_balance() print(single_bal) ### get transactions single_trans = api.get_transaction_page(page=1, offset=10) formatted_st = pd.DataFrame.from_dict(single_trans) formatted_st['timeStamp'] = pd.to_datetime(formatted_st['timeStamp'], unit='s') print(formatted_st.head(5)) ### get blocks mined single_bm = api.get_blocks_mined_page(page=1, offset=10) formatted_bm = pd.DataFrame.from_dict(single_bm) formatted_bm['timeStamp'] = pd.to_datetime(formatted_bm['timeStamp'], unit='s') print(formatted_bm.head(5)) ## multiple address
TOKEN = sys.argv[1] balances = {} if os.path.exists('balances.json'): with open('balances.json') as fd: balances = json.load(fd) count = 0 nb_contracts = 47518 with open('all_contract.csv') as fp: line = fp.readline() while line: address = line.split(',')[0] count += 1 if address == 'address' or address in balances: line = fp.readline() continue if count % 20 == 0: with open('balances.json', 'w') as fd: json.dump(balances, fd) print(count, '/', nb_contracts, round(count * 100 / nb_contracts, 2), '%') try: api = Account(address=address, api_key=TOKEN) balance = int(api.get_balance()) balances[address] = balance except Exception as identifier: print(identifier) continue line = fp.readline()
def scan(): api = Account(address=eth_addy, api_key=etherscan_key) balance = api.get_balance() return int(balance[:-15]) / 1000