Usage
Note
The endpoints are not filtered on a per-chain basis. Refer to blockscan docs in case your call fails.
Prerequisite
This package to be installed (
pip install blockscan-python)- The chain ID you want to connect to.
Refer to chainlist if unknown
- Specific chain API Token provided by blockscan
(i.e: An etherscan.io token for Ethereum)
Exception: Any Blockscout chain takes an empty string “”, No token required
Create a connection client
The connection can be created as Sync:
>>> from blockscan import Blockscan
# Sync connection to etherscan.io
>>> client = blockscan(1, "MYAPITOKEN", is_async=False)
>>> client.accounts.get_currency_balance(
"0x0000000000000000000000000000000000000000"
)
'11400022397988649428803'
But will default to Async if no parameter is provided:
>>> from blockscan import BlockScan
#Async connection to bscscan.com
>>> client = Blockscan(56, "MYAPITOKEN")
>>> bal = await client.accounts.get_currency_balance(
"0x0000000000000000000000000000000000000000"
)
>>> print(bal)
'1073557893975925234717'
See below for the full list of parameters available:
- class blockscan.Blockscan(chain_id: int, api_key: str, is_async: bool = True, modules: Optional[Dict[str, Module]] = None, debug: bool = False, pro: bool = False, testing: bool = False)[source]
Create a new client with the provided modules
- Parameters
chain_id (int) – The specific blockchain ID (i.e Polygonscan == 137)
api_key (str) – Your blockscan API KEY (blockchain specific)
is_async (bool, optional) – Whether you want an async client or not, defaults to True
modules (Optional[Dict[str, Module]], optional) – Modules to be attached to the client, if none is provided it will fetch all. Formated as
{"module": Module}debug (bool, optional) – Display generated URLs for debugging, defaults to False
pro (bool, optional) – Also attach the Pro modules to the client. Overwritten if modules are manually provided, default to False
testing (bool, optional) – apply only to sync, will return the json data necessary for the unittests, use only for developping purpose. defaults to False
- Returns
A connection client
- Return type
BaseConnection