Skip to main content

A python API for bscscan.com with support for BSC Testnet

Project description

bscscan-python

A complete Python API for BscScan.com

Powered by BscScan.com APIs

Available on PyPI

:book: Read the official documentation here :book:

👇

A fork of the etherscan-python package.

Fork

Modified version hosted at https://github.com/gabr1e11/bscscan-python that supports BSC Tesnet

See Usage below for an example of how to use the package for the testnet

Endpoints

The following endpoints are provided:

Accounts (source)

  • get_bnb_balance
  • get_bnb_balance_multiple
  • get_normal_txs_by_address
  • get_normal_txs_by_address_paginated
  • get_internal_txs_by_address
  • get_internal_txs_by_address_paginated
  • get_internal_txs_by_txhash
  • get_internal_txs_by_block_range_paginated
  • get_bep20_token_transfer_events_by_address
  • get_bep20_token_transfer_events_by_contract_address_paginated
  • get_bep20_token_transfer_events_by_address_and_contract_paginated
  • get_bep721_token_transfer_events_by_address
  • get_bep721_token_transfer_events_by_contract_address_paginated
  • get_bep721_token_transfer_events_by_address_and_contract_paginated
  • get_validated_blocks_by_address
  • get_validated_blocks_by_address_paginated
Contracts (source)

  • get_contract_abi
  • get_contract_source_code
Transactions (source)

  • get_tx_receipt_status
Blocks (source)

  • get_block_reward_by_block_number
  • get_est_block_countdown_time_by_block_number
  • get_block_number_by_timestamp
GETH/Parity Proxy (source)

  • get_proxy_block_number
  • get_proxy_block_by_number
  • get_proxy_block_transaction_count_by_number
  • get_proxy_transaction_by_hash
  • get_proxy_transaction_by_block_number_and_index
  • get_proxy_transaction_count
  • get_proxy_transaction_receipt
  • get_proxy_call
  • get_proxy_code_at
  • get_proxy_storage_position_at
  • get_proxy_gas_price
  • get_proxy_est_gas
Tokens (source)

  • get_total_supply_by_contract_address
  • get_circulating_supply_by_contract_address
  • get_acc_balance_by_token_contract_address
Stats (source)

  • get_total_bnb_supply
  • get_validators_list
Logs (source)

  • get_logs

If you think that a newly-added method is missing, kindly open an issue as a feature request and I will do my best to add it.

Installation

Before proceeding, you should register an account on BscScan.com and generate a personal API key to use.

Install from source:

pip install git+https://github.com/pcko1/bscscan-python.git@stable

Alternatively, install from PyPI:

pip install bscscan-python

Unit tests

In bash, test that everything looks OK on your end using your YOUR_API_KEY (without quotation marks):

bash run_tests.sh YOUR_API_KEY

Note: This will install the coverage package in your activated python environment.

Usage

In python, create a client with your personal BscScan.com API key:

import asyncio
from bscscan import BscScan

YOUR_API_KEY = "..."

async def main():
  async with BscScan(YOUR_API_KEY) as bsc:
    print(await bsc.get_bnb_balance(address="0x0000000000000000000000000000000000001004"))

if __name__ == "__main__":
  asyncio.run(main())

> '167195709084498025431541166'

For the BSC Testnet you can pass a the testnet parameter set to True to connect to the Testnet:

import asyncio
from bscscan import BscScan

YOUR_API_KEY = "..."

async def main():
  async with BscScan(YOUR_API_KEY, testnet=True) as bsc:
    print(await bsc.get_bnb_balance(address="0x0000000000000000000000000000000000001004"))

if __name__ == "__main__":
  asyncio.run(main())

> '167195709084498025431541166'

Examples

Detailed examples (arguments and results) for all methods may be found in the official documentation. Documentation Status

Issues

For problems regarding installing or using the package please open an issue. Kindly avoid disclosing potentially sensitive information such as your API keys or your wallet addresses.

Cite

Kotsias, P. C., pcko1/bscscan-python: v1.0.0. https://github.com/pcko1/bscscan-python (2021). doi:10.5281/zenodo.4781726

or in bibtex:

@misc{Kotsias2020,
  author = {Kotsias, P.C.},
  title = {pcko1/bscscan-python},
  year = {2021},
  publisher = {Zenodo},
  url = {https://github.com/pcko1/bscscan-python},
  doi = {10.5281/zenodo.4781726}
}

Roberto Cano, gabr1e11/bscscan-python: v2.0.1 https://github.com/gabr1e11/bscscan-python (2021).

or in bibtex:

@misc{RobertoCano2021,
  author = {Roberto Cano},
  title = {gabr1e11/bscscan-python},
  year = {2021},
  url = {https://github.com/gabr1e11/bscscan-python},
}

Feel free to leave a :star: if you found this package useful.


Powered by Bscscan.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

bscscan-python-testnet-2.0.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bscscan_python_testnet-2.0.1-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file bscscan-python-testnet-2.0.1.tar.gz.

File metadata

  • Download URL: bscscan-python-testnet-2.0.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for bscscan-python-testnet-2.0.1.tar.gz
Algorithm Hash digest
SHA256 e620b3b98f7b2ebc5337573602b54040ad8a3a677c44fcbc57304596abf0dffb
MD5 45a03466a30392125465abf79f5a2894
BLAKE2b-256 b840570622570ff0eac774ba8147854044149293ca652afeddd9d337a9c203b3

See more details on using hashes here.

File details

Details for the file bscscan_python_testnet-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: bscscan_python_testnet-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for bscscan_python_testnet-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 215d14750f20b06cc0a33209725ca83ecea099f50a027c204ab6a122ee07d334
MD5 d4337e5d5bd6f932d914ff68b0be5847
BLAKE2b-256 deea8e0dfbedca7d95305bd3fd66abfee604ab523b918e09167da9baf7b03271

See more details on using hashes here.

Supported by

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