コード例 #1
0
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
コード例 #2
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_all_blocks_mined(offset=10000, blocktype='uncles')
print(blocks)
コード例 #3
0
def get_all_blocks_mined(address, blocktype):
    api = Account(address=address, api_key=key)
    blocks = api.get_all_blocks_mined(offset=10000, blocktype=blocktype)
    print(blocks)