Python API for blockscout.com explorers
Project description
blockscout-python
Python API for blockscout.com as currently tested on:
REST Endpoints
The following REST endpoints are provided:
Accounts (source) (test notebook)
get_addresses
get_address_info
get_address_counters
get_address_transactions
get_address_logs
get_blocks_validated
get_token_balances
get_token_balances_with_filtering
get_coin_balance_history
get_coin_balance_history_by_day
Block (source) (test notebook)
get_block_info
get_block_transactions
get_block_withdrawals
get_main_page_blocks
Contract (source) (test notebook)
get_smart_contracts
get_smart_contract_counters
get_smart_contract
Tokens (source) (test notebook)
get_tokens_list
get_token_info
get_token_transfers
get_token_holders
get_token_counters
Transactions (source) (test notebook)
get_state_changes
get_transaction_logs
get_internal_transactions
get_token_hash_transfers
get_transaction_info
get_main_page_transactions
RPC Endpoints
The following RPC endpoints are provided:
Accounts (source) (test notebook)
get_balance
get_pending_txs_by_address_paginated
get_txs_by_address_paginated
get_erc20_token_transfer_events_by_address
get_erc721_token_transfer_events_by_address
get_erc20_balance_by_contract_address
get_erc20_tokens_by_address
get_account_list_balances
Block (source) (test notebook)
get_block_reward_by_block_number
get_est_block_countdown_time_by_block_number
get_block_number_by_timestamp
Contract (source) (test notebook)
get_contract_list
get_contract_abi
get_source_code
get_contract_creation
Stats (source) (test notebook)
get_total_token_supply
get_total_eth_supply
get_total_coin_supply
get_eth_price
get_coin_price
Tokens (source) (test notebook)
get_total_supply_by_contract_address
get_total_holders_by_contract_address
get_tx_info
get_tx_receipt_status
get_status
Installation
Install from source:
pip install git+https://github.com/defipy-devs/blockscout-python.git
Alternatively, install from PyPI:
pip install blockscout-python
Basic Usage
from blockscout import Blockscout
from blockscout import Net
eth = Blockscout(Net.ROLLUX, API.RPC)
Then you can call all available methods, e.g.:
eth.get_balance(address="0xBb8b9456F615545c88528653024E87C6069d1598")
> {'message': 'OK', 'result': '2010991698475838058402243', 'status': '1'}
Token Transfers: Time Series
- See test notebook for example
Pull data for specified address
from blockscout import TokenTransfers
from blockscout import Net
addr = '0x8A4AA176007196D48d39C89402d3753c39AE64c1'
tkn_trans = TokenTransfers(Net.ROLLUX)
dict_transfers = tkn_trans.apply(addr)
tkn_balances = tkn_trans.get_tkn_balances()
tkn_balances
OUTPUT:
{'USDT': {'tkn_balance': 89590009236, 'tkn_decimal': 6},
'USDC': {'tkn_balance': 238003477125, 'tkn_decimal': 6},
'ETH': {'tkn_balance': 2689089808644384766235, 'tkn_decimal': 18},
'BTC': {'tkn_balance': 999799972, 'tkn_decimal': 8},
'WSYS': {'tkn_balance': 65787771636449164370510, 'tkn_decimal': 18}}
Plot token transfers
import matplotlib.pyplot as plt
tkn_symbol = 'USDC'
dates, tkn_coin_balances = tkn_trans.get_tkn_timeseries(dict_transfers, tkn_symbol)
fig, (TKN_ax) = plt.subplots(nrows=1, sharex=False, sharey=False, figsize=(16, 3))
TKN_ax.plot(dates, tkn_coin_balances, color = 'r',linestyle = 'dashdot', label=tkn_symbol)
TKN_ax.set_ylabel(f'{tkn_symbol} Balance', size=14)
TKN_ax.set_xlabel('Date', size=14)
Coin Transfers: Time Series
- See test notebook for example
Pull data for specified address
from blockscout import CoinTransfers
from blockscout import Net
addr = '0x8A4AA176007196D48d39C89402d3753c39AE64c1'
coin_trans = CoinTransfers(Net.ROLLUX)
txs = coin_trans.pull_coin_transactions(addr)
coin_tx = coin_trans.pull_coin_balances(addr, txs)
Plot token transfers
import matplotlib.pyplot as plt
tkn_symbol = 'SYS'
dates, tkn_coin_balances = coin_trans.get_tkn_timeseries(coin_tx)
fig, (TKN_ax) = plt.subplots(nrows=1, sharex=False, sharey=False, figsize=(16, 3))
TKN_ax.plot(dates, tkn_coin_balances, color = 'r',linestyle = 'dashdot', label=tkn_symbol)
TKN_ax.set_ylabel(f'{tkn_symbol} Balance', size=14)
TKN_ax.set_xlabel('Date', size=14)
If you found this package helpful, please leave a :star:!
Powered by Blockscout.com APIs.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.