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)
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)
Пример #3
0
 def test_get_balance_multi(self):
     api = Account(address=MULTI_ACCOUNT, api_key=API_KEY)
     self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE)
Пример #4
0
 def test_get_balance_multi(self):
     api = Account(address=MULTI_ACCOUNT, api_key=API_KEY)
     self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE)
Пример #5
0
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)
Пример #6
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
Пример #7
0
    '0x847830bcf9135dc4548a64a55ca2b48a8a75c9bb',
    '0xD9E68069917393974A464e25F123F22C208afc1D',
    '0xD3db32545817a0574938Dc0ab27697699A86efed',
    '0x53c7a8d887d8517aa5a8b268ad48caab20a53a50',
    '0xa4aAA1B5f371Ac9Df6DB74b4aaAB4cAe91810ce8',
    '0x036BBfafae484e8964d861822C9415707b694D4E',
    '0x17AB69ccE747130a5faC74Cb033A3Fa9eFb26d41',
    '0xCdCd8B86263496270568D6CA74626038Bb6c7Edf',
    '0xA5aaC3ff6a6eA1134037752F8eaB76c1854c12e0'
]

address_extra = [
    '0xcf6f8CC2B2B2f06F9Cf2c2f919BB8b128F3D0FFA',
    '0x63ECc6c4594171289a304FCb9e3829cC35Eb6b9C'
]

api = Account(address=address, api_key=key)
balances = api.get_balance_multiple()
balances_show = [{
    'account': info.get('account'),
    'balance': float(info.get('balance')) / math.pow(10, 18)
} for info in balances]
print(balances_show)

api = Account(address=address_extra, api_key=key)
balances_extra = api.get_balance_multiple()
balances_extra_show = [{
    'account': info.get('account'),
    'balance': float(info.get('balance')) / math.pow(10, 18)
} for info in balances_extra]
print(balances_extra_show)
Пример #8
0
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)
### get reward
reward = api.get_block_reward(block)
print(reward)

# Contracts
address = '0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359'
### get abi
api = Contract(address=address, api_key=key)
abi = api.get_abi()