def ico_chart_data(token_name): key = 'F3C5GJBZ611TXR77PFERXB56R5VD1P9YUD' try: address = provider.search(token_name)['ico'] web3 = get_web3_provider() account = Account(address=address, api_key=key) transactions = account.get_all_transactions(offset=1000, sort='asc', internal=True) data_frame = pd.DataFrame(transactions) data_frame = data_frame[(data_frame['isError'] != '1')] data_frame['datetime'] = pd.to_datetime(data_frame['timeStamp'], unit='s') data_frame['value'] = data_frame['value'].apply( lambda x: web3.fromWei(int(x), 'ether')) data_frame = data_frame[data_frame['value'] > 0] data_frame['date'] = data_frame['datetime'].dt.date data_frame['blockNumber'] = data_frame['blockNumber'].apply( lambda x: int(x)) data_group = data_frame.groupby('blockNumber')['value', 'isError'].sum() data_group['index'] = data_group.index labels = data_group['index'].as_matrix() min_label = labels.min() max_label = labels.max() labels = (labels - min_label) * 100 / (max_label - min_label) values = data_group['value'].as_matrix() cumulative_values = values.cumsum() total = values.sum() cumulative_values = cumulative_values * 100 / total return labels, cumulative_values except: return None
def get_stakes(): with open('config.json') as config_file: data = json.load(config_file) if "etherscan_api_token" not in data.keys( ) or data['etherscan_api_token'] == "": raise Exception("etherscan_api_token must be specified in config.json") key = data['etherscan_api_token'] stake_address = '0x370f4d7625c10499bbb9353f3e91f83a0b750bec' api = Account(address=stake_address, api_key=key) transactions = api.get_transaction_page(page=1, offset=10000, sort='des', erc20=True) total_in = 0 total_out = 0 stargates = 0 for t in transactions: if t["tokenName"] == "DADI" and t["to"] == stake_address: value = int(t["value"]) / 1e18 total_in += value if value == 5e5: stargates += 1 elif t["from"] == stake_address and t[ "to"] != "0xef45b79def79a2cd2d0c77f84fddaab8d0b8be35": total_out = value if value == 5e5: stargates -= 1 total_staked = total_in - total_out stargates_staked = stargates * 5e5 hosts_staked = total_staked - stargates_staked return total_staked, hosts_staked, stargates_staked
def get_balance_multiple(address): api = Account(address=address, api_key=key) balances = api.get_balance_multiple() balances = pd.DataFrame(balances) balances.to_csv( r'C:\Yiru Xiong-Professional\实习\CryptoAlgoWheel\S1\task3\S1_task3_accounts_balancemultiple.csv', index=False)
def watch(self): count = 0 while True: for name, address in self.address_book.items(): print(f"{count} looking through {name}'s address") acc = Account(address=address, api_key=self.key) transactions = acc.get_transaction_page(page=0, sort ='desc', erc20=True) if len(transactions) < 50: upper_range = len(transactions) else: upper_range = 50 for i in range(0,upper_range): curr_tx = transactions[i] token_name = curr_tx['tokenName'] if token_name not in self.influencer_dicts[name]: print(f"New token {token_name} found by {name}") if token_name not in self.shared_coins: self.shared_coins[token_name] = 0 discord_notif.notif(curr_tx, name, token_name, self.shared_coins[token_name], True) else: self.shared_coins[token_name] += 1 discord_notif.notif(curr_tx, name, token_name, self.shared_coins[token_name]) self.influencer_dicts[name][token_name] = True discord_notif.update_json(name, token_name, self.influencer_dicts[name], self.shared_coins) count += 1 print('waiting') time.sleep(10)
def get_blocks_mined_page(address, page, offset, blocktype): api = Account(address=address, api_key=key) blocks = api.get_blocks_mined_page(page=page, offset=offset, blocktype=blocktype) blocks = pd.DataFrame(blocks) blocks.to_csv( r'C:\Yiru Xiong-Professional\实习\CryptoAlgoWheel\S1\task3\S1_task3_accounts_minedpage.csv', index=False)
def get_transaction_page(address, page, offset, sort): api = Account(address=address, api_key=key) transactions = api.get_transaction_page(page=page, offset=offset, sort=sort) transactions = pd.DataFrame(transactions) transactions.to_csv( r'C:\Yiru Xiong-Professional\实习\CryptoAlgoWheel\S1\task3\S1_task3_accounts_transactionpage.csv', index=False)
def __init__(self, _add, _web3): self.add = _add self.web3 = _web3 with open('apiKey.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] self.api = Account(address=_add, api_key=key)
def plot_ether_transactions(address): from etherscan.accounts import Account with open('etherscan_api_key.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] api = Account(address=address, api_key=key) transactions = api.normal_transactions() print(transactions)
def get_transaction_page_erc20(address, page, offset, sort, erc20): api = Account(address=address, api_key=key) transactions = api.get_transaction_page(page=1, offset=10000, sort='des', erc20=True) transactions = pd.DataFrame(transactions) transactions.to_csv( r'C:\Yiru Xiong-Professional\实习\CryptoAlgoWheel\S1\task3\pageerc20.csv', index=False)
def main(): if len(sys.argv) < 2: print("usage: " + os.path.basename(__file__) + " user_wallet") sys.exit(1) else: wallet_addy = str(sys.argv[1]) address = wallet_addy api = Account(address=wallet_addy, api_key=key) transactions = api.get_all_transactions(offset=10000, sort='des', internal=False) pprint.pprint(transactions)
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 checkIfRelayed(address): #check if a transcation has been sent to the consensus within the last 3 hours time_now_utc = datetime.utcnow() unixtime = calendar.timegm(time_now_utc.utctimetuple()) api = Account(address=Web3.toChecksumAddress(address), api_key="") transactions = api.get_transaction_page(page=1, offset=10, sort='des', internal=False) relayed = False for trans in transactions: if Web3.toChecksumAddress(trans['to']) == Web3.toChecksumAddress( '0x3014ca10b91cb3D0AD85fEf7A3Cb95BCAc9c0f79'): if int(trans['timeStamp']) > (unixtime - 60 * 60 * HOURS_TO_SEARCH_BACK): relayed = True break return relayed
class reader(): add = None web3 = None api = None def __init__(self, _add, _web3): self.add = _add self.web3 = _web3 with open('apiKey.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] self.api = Account(address=_add, api_key=key) def read(self, _nr): transactions = self.api.get_transaction_page(page=1, offset=10000, sort='des') return transactions[_nr]
def test_get_balance_multi(self): api = Account(address=MULTI_ACCOUNT, api_key=API_KEY) self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE)
def test_get_balance(self): api = Account(address=SINGLE_ACCOUNT, api_key=API_KEY) self.assertEqual(api.get_balance(), SINGLE_BALANCE)
def get_all_transactions(): api = Account(address=ADDRESS, api_key=ether_key) transactions = api.get_all_transactions(offset=10000, sort='asc', internal=True) return transactions
def get_single_transaction_page(): api = Account(address=ADDRESS, api_key=API_KEY) transactions = api.get_transaction_page(page=1, offset=10000, sort='des') return transactions
from etherscan.accounts import Account import json with open('./etherscan.json', mode='r') as key_file: key = json.loads(key_file.read())['key'] address = ['0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'] api = Account(address=address, api_key=key) balances = api.get_balance_multiple() print(balances)
from etherscan.proxies import Proxies from etherscan.stats import Stats 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()
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 = '0x49edf201c1e139282643d5e7c6fb0c7219ad1db7' api = Account(address=address, api_key=key) transactions = api.get_all_transactions(offset=10000, sort='asc', internal=False) print(transactions[0])
from etherscan.accounts import Account import json address = '0x491179f035fdf219798d186f576abdf842c14ca6' api = Account(address=address, api_key='ZD8EBE2I7GCGG8Y8YNY2PMD2GT3P2UIJ55') transactions = api.get_transaction_page(page=1, offset=10000, sort='des') print(transactions)
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', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'] address = '0x5bda447c0c2ade0a0b6daf22c88505f9e55f0c61 ' api = Account(address=address, api_key=key) transactions = api.get_all_transactions(offset=10000, sort='asc') print(transactions[0])
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 = '0x2a65aca4d5fc5b5c859090a6c34d164135398226' api = Account(address=address, api_key=key) blocks = api.get_blocks_mined_page(page=1, offset=10000, blocktype='blocks') print(blocks)
from etherscan.accounts import Account import json key = '59W93VKBDTSR1V8EQTBGYDWEVZEIYIPHCV' address = '0xb794f5ea0ba39494ce839613fffba74279579268' 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) transactions = api.get_transaction_page(page=1, offset=10000, sort='des') print(transactions)
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) transactions = api.get_transaction_page(page=1, offset=10000, sort='des', erc20=True) print(transactions)
def deployer_watcher(address, key): acc = Account(address=address, api_key=key) transactions = acc.get_transaction_page(page=1, offset=10000, sort='des', erc20=True) for transaction in transactions: if transaction['from'] == 'ADDRESS_HERE': print(transaction)
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 get_transaction_by_address(address, asset, page): address = address.lower() try: mongo_client.insert_address(address) except Exception as e: app_logger.error(e) txs = [ tx for tx in mongo_client.get_transfer_records(address, asset, page) ] new_txs = [] for tx in txs: if tx["txReceiptStatus"] == "0": tx["txReceiptStatus"] = "-1" tx["addressFrom"] = checksum_encode(tx["addressFrom"]) tx["addressTo"] = checksum_encode(tx["addressTo"]) new_txs.append(tx) if page != 1: return new_txs else: if new_txs: return new_txs my_account = Account(address=address, api_key=setting.API_KEY) my_account.PREFIX = setting.ETHSCAN_API_PREFIX try: res = my_account.get_transaction_page(sort="desc") except: res = None if res: tmp_list_0x = [] tmp_list_contract = [] for r in res: tmp_dict = {} input_data = r.get("input") if r.get("to") == asset and input_data[:10] == "0xa9059cbb": tmp_dict["addressFrom"] = checksum_encode(r.get("from")) tmp_dict["addressTo"] = checksum_encode(input_data[34:74]) tmp_dict["value"] = str(int(input_data[74:], 16)) tmp_dict["txId"] = r.get("hash") tmp_dict["gasUsed"] = r.get("gasUsed") tmp_dict["gasPrice"] = r.get("gasPrice") tmp_dict["gas"] = r.get("gas") tmp_dict["blockNumber"] = r.get("blockNumber") tmp_dict["blockTime"] = r.get("timeStamp") tmp_dict["asset"] = r.get("to") tmp_dict["txReceiptStatus"] = r.get( "txreceipt_status" ) if r.get("txreceipt_status") != "0" else "-1" tmp_list_contract.append(tmp_dict) if input_data == "0x" and asset == "0x00000000000000000000000000000000000000": tmp_dict["addressFrom"] = checksum_encode(r.get("from")) tmp_dict["addressTo"] = checksum_encode(r.get("to")) tmp_dict["value"] = r.get("value") tmp_dict["txId"] = r.get("hash") tmp_dict["gasUsed"] = r.get("gasUsed") tmp_dict["gasPrice"] = r.get("gasPrice") tmp_dict["gas"] = r.get("gas") tmp_dict["blockNumber"] = r.get("blockNumber") tmp_dict["blockTime"] = r.get("timeStamp") tmp_dict["asset"] = "0x00000000000000000000000000000000000000" tmp_dict["txReceiptStatus"] = r.get( "txreceipt_status" ) if r.get("txreceipt_status") != "0" else "-1" tmp_list_0x.append(tmp_dict) if asset == "0x00000000000000000000000000000000000000": tmp_list = tmp_list_0x else: tmp_list = tmp_list_contract if len(tmp_list) > 8: return tmp_list[:8] return tmp_list return []
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
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 = '0x2a65aca4d5fc5b5c859090a6c34d164135398226' api = Account(address=address, api_key=key) blocks = api.get_all_blocks_mined(offset=10000, blocktype='uncles') print(blocks)
def __init__(self, address): super().__init__() self.address = address self.api = Account(address=address, api_key=self.key) self._create_data_folder(DATA_DIR)
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', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'] api = Account(address=address, api_key=key) balances = api.get_balance_multiple() print(balances)
key = json.loads(key_file.read())['key'] ponzi = [] # Reads Ponzi addresses from ponzi_file, and writes them to array ponzi with open(ponzi_file) as f: reader = csv.reader(f, delimiter=',', quotechar='|') for row in reader: addr = row[0] ponzi.append(addr) for addr in ponzi: if (verbose): print("Retrieving transactions of contract ",addr,"... ",end=" ") sys.stdout.flush() api = Account(address=addr, api_key=key) text = api.get_ext_transactions() tint = api.get_int_transactions() if (verbose): print("done") count_text = 0 count_tint = 0 eth_text = 0 eth_tint = 0 usd_text = 0 usd_tint = 0 users_text = set() users_tint = set() date_first_tx = '' date_last_tx = ''
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', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'] address = '0x49edf201c1e139282643d5e7c6fb0c7219ad1db7' api = Account(address=address, api_key=key) transactions = api.get_all_transactions(offset=10000, sort='asc', internal=True) print(transactions[0])