Skip to main content

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.

Metadata

Release files for blockscout-python 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blockscout-python 0.1.2
File Size Uploaded Provenance Actions
blockscout_python-0.1.2.tar.gz 15.2 kB Without provenance Details for blockscout_python-0.1.2.tar.gz

Release files / blockscout_python-0.1.2.tar.gz

Download URL blockscout_python-0.1.2.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6c60ff4aff2aa67d318cbd8f6b72a97c684d708e1d1b486dc40ae0f49ff8cc80
BLAKE2b-256 checksum
How to use checksums
ee09db0b89964179b5c612b387c7da4b36861851d5dac6858a3543e547141fdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.0rc2

Security for blockscout-python 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page