Skip to main content

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
Stats (source) (test notebook)

  • get_stats_transactions_chart
  • get_stats_counters
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

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)

plot

Coin Transfers: Time Series

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)

plot

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.

Source Distribution

blockscout_python-0.1.2.tar.gz (15.2 kB view details)

Uploaded Source

File details

Details for the file blockscout_python-0.1.2.tar.gz.

File metadata

  • Download URL: blockscout_python-0.1.2.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.0rc2

File hashes

Hashes for blockscout_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6c60ff4aff2aa67d318cbd8f6b72a97c684d708e1d1b486dc40ae0f49ff8cc80
MD5 94945adfb81a32f5d0e1831244ccfad3
BLAKE2b-256 ee09db0b89964179b5c612b387c7da4b36861851d5dac6858a3543e547141fdf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page