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)
Ejemplo n.º 2
0
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)

# Blocks

api = Blocks(api_key=key)

reward = api.get_block_reward(2165403)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
## 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
addresses = ['0xbb9bc244d798123fde783fcc1c72d3bb8c189413', '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a']
api = Account(address=addresses, api_key=key)
### get balance
mutiple_bal = api.get_balance_multiple()
formatted_mb = pd.DataFrame.from_dict(mutiple_bal)
print(formatted_mb.head(5))

# Blocks
block = 2165403
api = Blocks(api_key=key)
Ejemplo n.º 5
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)