bscscan.modules package

Submodules

bscscan.modules.accounts module

class bscscan.modules.accounts.Accounts

Bases: object

static get_bep20_token_transfer_events_by_address(address: str, startblock: int, endblock: int, sort: str)

Get all BEP20 token transfer events for a given address.

NOTE: Returns the 10,000 most recent events.

Parameters
  • address (str) – Target address.

  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • sort (str) – “asc” to return results in ascending order.

Returns

All token transfers for target address.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep20_token_transfer_events_by_address(
            address="0x63aea877b5d5fa234a1532f1b26a4f6d9051866e",
            startblock=0,
            endblock=999999999,
            sort="asc"
        )
    )

Results:

[
    {
        "blockNumber": "4387931",
        "timeStamp": "1611843685",
        "hash": "0x9603a00eaad4572fc03aae6ce4e64d129767752da95f53e3f726ad4ed86a843e",
        "nonce": "0",
        "blockHash": "0x33667c5034de6cb748e2d746b31b21f2c90dc20e8b670658bbb1c2201ced17f3",
        "from": "0x7be44b47c12761eab1b80b5779638fb09165c743",
        "contractAddress": "0xe9e7cea3dedca5984780bafc599bd69add087d56",
        "to": "0x63aea877b5d5fa234a1532f1b26a4f6d9051866e",
        "value": "42265483120736185167",
        "tokenName": "Binance-Peg BUSD Token",
        "tokenSymbol": "BUSD",
        "tokenDecimal": "18",
        "transactionIndex": "8",
        "gas": "411698",
        "gasPrice": "20000000000",
        "gasUsed": "286489",
        "cumulativeGasUsed": "1154025",
        "input": "deprecated",
        "confirmations": "3196712"
    },

    ...
]
static get_bep20_token_transfer_events_by_address_and_contract_paginated(contract_address: str, address: str, page: int, offset: int, sort: str)

Get all token transfers for a given BEP20 contract and wallet as numbered pages.

Parameters
  • contract_address (str) – Target contract address.

  • address (str) – Target wallet address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • sort (str) – “asc” to return results in ascending order.

Returns

All token transfers as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep20_token_transfer_events_by_address_and_contract_paginated(
            "contract_address": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
            "address": "0x63aea877b5d5fa234a1532f1b26a4f6d9051866e",
            "page": 1,
            "offset": 100,
            "sort": "asc"
        )
    )

Results:

[
    {
        "blockNumber": "4505611",
        "timeStamp": "1612197293",
        "hash": "0x3ac8603f421ccc08e198e4d06f05b8b31dc76b747369d78f3e7fa489f4692c44",
        "nonce": "43",
        "blockHash": "0x3ea200d5770ce8fcfa17754fad9143c77ab9ef5c3a5bd9ceb18c13a40ec6e926",
        "from": "0x7be44b47c12761eab1b80b5779638fb09165c743",
        "contractAddress": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
        "to": "0x63aea877b5d5fa234a1532f1b26a4f6d9051866e",
        "value": "98000000000000000000",
        "tokenName": "Wrapped BNB",
        "tokenSymbol": "WBNB",
        "tokenDecimal": "18",
        "transactionIndex": "127",
        "gas": "209173",
        "gasPrice": "20000000000",
        "gasUsed": "130773",
        "cumulativeGasUsed": "6294816",
        "input": "deprecated",
        "confirmations": "3079034"
    },

    ...
]
static get_bep20_token_transfer_events_by_contract_address_paginated(contract_address: str, page: int, offset: int, sort: str)

Get all token transfer events for a given BEP20 contract as numbered pages.

NOTE: Returns the 10,000 most recent events.

Parameters
  • contract_address (str) – Target contract address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • sort (str) – “asc” to return results in ascending order.

Returns

All token transfers for target contract address.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep20_token_transfer_events_by_contract_address_paginated(
            contract_address="0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
            page=1,
            offset=100,
            sort="asc"
        )
    )

Results:

[
    {
        "blockNumber": "188549",
        "timeStamp": "1599237427",
        "hash": "0x817585be21abae212524b1f86fb0c6ceaff0048ae4a29739108476b2ca06290e",
        "nonce": "16",
        "blockHash": "0x499c458e0ba984af9a2d1a188e2ba36c117f7a7eeba7ee23471e85b01653e10c",
        "from": "0x72af20bdae54756576b3725e73b75391e599a191",
        "contractAddress": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
        "to": "0x72af20bdae54756576b3725e73b75391e599a191",
        "value": "10000000000000000",
        "tokenName": "Wrapped BNB",
        "tokenSymbol": "WBNB",
        "tokenDecimal": "18",
        "transactionIndex": "0",
        "gas": "45614",
        "gasPrice": "22000000000",
        "gasUsed": "28382",
        "cumulativeGasUsed": "28382",
        "input": "deprecated",
        "confirmations": "7396096"
    },

    ...
]
static get_bep721_token_transfer_events_by_address(address: str, startblock: int, endblock: int, sort: str)

Get all BEP721 token transfer events for a given address.

NOTE: Returns the 10,000 most recent events.

Parameters
  • address (str) – Target address.

  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • sort (str) – “asc” to return results in ascending order.

Returns

All token transfers for target address.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep721_token_transfer_events_by_address(
            address=0xcd4ee0a77e09afa8d5a6518f7cf8539bef684e6c",
            startblock=0,
            endblock=999999999,
            sort=asc"
        )
    )

Results:

[
    {
        "blockNumber": "2657100",
        "timeStamp": "1606646313",
        "hash": "0x43485c443c235156777148dddcc1483a1c8f46cccf5ab185cfc4bd678f247b6b",
        "nonce": "6",
        "blockHash": "0x20b6e2e67e74badc19b225a0aa4febe2382569c99842e32bc9d5dc94631a349d",
        "from": "0x0000000000000000000000000000000000000000",
        "contractAddress": "0x5e74094cd416f55179dbd0e45b1a8ed030e396a1",
        "to": "0xcd4ee0a77e09afa8d5a6518f7cf8539bef684e6c",
        "tokenID": "384552",
        "tokenName": "Pancake Lottery Ticket",
        "tokenSymbol": "PLT",
        "tokenDecimal": "0",
        "transactionIndex": "2",
        "gas": "27000000",
        "gasPrice": "20000000000",
        "gasUsed": "22547256",
        "cumulativeGasUsed": "22947060",
        "input": "deprecated",
        "confirmations": "4927545"
    },

    ...
]
static get_bep721_token_transfer_events_by_address_and_contract_paginated(contract_address: str, address: str, page: int, offset: int, sort: str)

Get all token transfers for a given BEP721 contract and wallet as numbered pages.

Parameters
  • contract_address (str) – Target contract address.

  • address (str) – Target wallet address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • sort (str) – “asc” to return results in ascending order.

Returns

All token transfers as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep721_token_transfer_events_by_address_and_contract_paginated(
            "contract_address": "0x5e74094cd416f55179dbd0e45b1a8ed030e396a1",
            "address": "0xcd4ee0a77e09afa8d5a6518f7cf8539bef684e6c",
            "page": 1,
            "offset": 100,
            "sort": "asc"
        )
    )

Results:

[
    {
        "blockNumber": "2657100",
        "timeStamp": "1606646313",
        "hash": "0x43485c443c235156777148dddcc1483a1c8f46cccf5ab185cfc4bd678f247b6b",
        "nonce": "6",
        "blockHash": "0x20b6e2e67e74badc19b225a0aa4febe2382569c99842e32bc9d5dc94631a349d",
        "from": "0x0000000000000000000000000000000000000000",
        "contractAddress": "0x5e74094cd416f55179dbd0e45b1a8ed030e396a1",
        "to": "0xcd4ee0a77e09afa8d5a6518f7cf8539bef684e6c",
        "tokenID": "384552",
        "tokenName": "Pancake Lottery Ticket",
        "tokenSymbol": "PLT",
        "tokenDecimal": "0",
        "transactionIndex": "2",
        "gas": "27000000",
        "gasPrice": "20000000000",
        "gasUsed": "22547256",
        "cumulativeGasUsed": "22947060",
        "input": "deprecated",
        "confirmations": "4927545"
    },

    ...
]
static get_bep721_token_transfer_events_by_contract_address_paginated(contract_address: str, page: int, offset: int, sort: str)

Get all token transfer events for a given BEP721 contract as numbered pages.

NOTE: Returns the 10,000 most recent events.

Parameters
  • contract_address (str) – Target contract address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • sort (str) – “asc” to return results in ascending order.

Returns

All token transfers for target contract address.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bep721_token_transfer_events_by_contract_address_paginated(
            contract_address="0x5e74094cd416f55179dbd0e45b1a8ed030e396a1",
            page=1,
            offset=100,
            sort="asc"
        )
    )

Results:

[
    {
        "blockNumber": "1592608",
        "timeStamp": "1603449812",
        "hash": "0x4d9d86b931bdaef28c2437d1dcf6bdbc9c80c5681cbf819726cad94c04edcd7a",
        "nonce": "391",
        "blockHash": "0x69e55bc5300dff5c5c009e818a0e8f71e0c895d1ce36da6b79182c860381524d",
        "from": "0x0000000000000000000000000000000000000000",
        "contractAddress": "0x5e74094cd416f55179dbd0e45b1a8ed030e396a1",
        "to": "0xb9fa21a62fc96cb2ac635a051061e2e50d964051",
        "tokenID": "1",
        "tokenName": "Pancake Lottery Ticket",
        "tokenSymbol": "PLT",
        "tokenDecimal": "0",
        "transactionIndex": "4",
        "gas": "1919509",
        "gasPrice": "20000000000",
        "gasUsed": "1260114",
        "cumulativeGasUsed": "1700085",
        "input": "deprecated",
        "confirmations": "5992037"
    },

    ...
]
static get_bnb_balance(address: str)

Get the BNB balance of an account.

Parameters

address (str) – Target account.

Returns

Its balance as a string. Must be manually cast to float.

Return type

str

Example:

from bscscan import BscScan

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

Results:

"158732998695887136972460565"
static get_bnb_balance_multiple(addresses: List[str])

Get the BNB balance of multiple accounts.

NOTE: Max 20 accounts per call are supported.

Parameters

addresses (List[str]) – List of target accounts.

Returns

Their balances in a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_bnb_balance_multiple(
            addresses=[
                "0x0000000000000000000000000000000000001004",
                "0x63a9975ba31b0b9626b34300f7f627147df1f526",
                "0x198ef1ec325a96cc354c7266a038be8b5c558f67"
            ]
        )
    )

Results:

[
    {
        "account": "0x0000000000000000000000000000000000001004",
        "balance": "158732998695887136972460565"
    },
    {
        "account": "0x63a9975ba31b0b9626b34300f7f627147df1f526",
        "balance": "0"
    },
    {
        "account": "0x198ef1ec325a96cc354c7266a038be8b5c558f67",
        "balance": "0"
    }
]
static get_internal_txs_by_address(address: str, startblock: int, endblock: int, sort: str)

Get a list of all internal transactions for an address.

NOTE: Returns the 10,000 most recent transactions.

Parameters
  • address (str) – Target address.

  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • sort (str) – “asc” to return results in ascending order.

Returns

A list of dictionaries of internal transactions.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_internal_txs_by_address(
            address="0x0000000000000000000000000000000000001004",
            startblock=0,
            endblock=2702578,
            sort="asc"
        )
    )

Results:

[
    {
        "blockNumber": "958",
        "timeStamp": "1598674477",
        "hash": "0x4d74a6fc84d57f18b8e1dfa07ee517c4feb296d16a8353ee41adc03669982028",
        "from": "0x0000000000000000000000000000000000001004",
        "to": "0x4e656459ed25bf986eea1196bc1b00665401645d",
        "value": "100000000000000",
        "contractAddress": "",
        "input": "",
        "type": "call",
        "gas": "12300",
        "gasUsed": "0",
        "traceId": "0_1_1",
        "isError": "0",
        "errCode": ""
    },

    ...
]
static get_internal_txs_by_address_paginated(address: str, page: int, offset: int, startblock: int, endblock: int, sort: str)

Get a list of all internal transactions for an address as numbered pages.

Parameters
  • address (str) – Target address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • sort (str) – “asc” to return results in ascending order.

Returns

All transactions on requested page as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_internal_txs_by_address_paginated(
            address="0x0000000000000000000000000000000000001004",
            startblock=0,
            endblock=2702578,
            page=1,
            offset=10,
            sort="asc",
        )
    )

Results:

[
    {
        "blockNumber": "958",
        "timeStamp": "1598674477",
        "hash": "0x4d74a6fc84d57f18b8e1dfa07ee517c4feb296d16a8353ee41adc03669982028",
        "from": "0x0000000000000000000000000000000000001004",
        "to": "0x4e656459ed25bf986eea1196bc1b00665401645d",
        "value": "100000000000000",
        "contractAddress": "",
        "input": "",
        "type": "call",
        "gas": "12300",
        "gasUsed": "0",
        "traceId": "0_1_1",
        "isError": "0",
        "errCode": ""
    },

    ...
]
static get_internal_txs_by_block_range_paginated(startblock: int, endblock: int, page: int, offset: int, sort: str)

Get all internal transactions given for a given block range as numbered pages.

NOTE: Returns the 10,000 most recent transactions.

Parameters
  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • sort (str) – “asc” to return results in ascending order.

Returns

All internal transactions as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_internal_txs_by_block_range_paginated(
            startblock=0,
            endblock=2702578,
            page=1,
            offset=10,
            sort="asc"
        )
    )

Results:

[
    {
    "blockNumber": "958",
    "timeStamp": "1598674477",
    "hash": "0x4d74a6fc84d57f18b8e1dfa07ee517c4feb296d16a8353ee41adc03669982028",
    "from": "0x0000000000000000000000000000000000001004",
    "to": "0x4e656459ed25bf986eea1196bc1b00665401645d",
    "value": "100000000000000",
    "contractAddress": "",
    "input": "",
    "type": "call",
    "gas": "12300",
    "gasUsed": "0",
    "traceId": "0_1_1",
    "isError": "0",
    "errCode": ""
    },

    ...
]
static get_internal_txs_by_txhash(txhash: str)

Get all internal transactions given for a tx hash.

NOTE: Returns the 10,000 most recent transactions.

Parameters

txhash (str) – Target tx hash.

Returns

All internal transactions as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_internal_txs_by_txhash(
            txhash="0x6dbc8f3e1ba98c63463b19ebef957ccd842db274ed499a54f2cdde8499604d54"
        )
    )

Results:

[
    {
        "blockNumber": "5012927",
        "timeStamp": "1613725978",
        "from": "0xcde540d7eafe93ac5fe6233bee57e1270d3e330f",
        "to": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
        "value": "21820550428160139857",
        "contractAddress": "",
        "input": "",
        "type": "call",
        "gas": "117864",
        "gasUsed": "22674",
        "isError": "0",
        "errCode": ""
    },

    ...
]
static get_normal_txs_by_address(address: str, startblock: int, endblock: int, sort: str)

Get a list of all normal transactions for an address.

NOTE: Returns the 10,000 most recent transactions.

Parameters
  • address (str) – Target address.

  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • sort (str) – “asc” to return results in ascending order.

Returns

A list of dictionaries of normal transactions.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_normal_txs_by_address(
            address="0x35e7a025f4da968de7e4d7e4004197917f4070f1",
            startblock=0,
            endblock=99999999,
            sort="asc"
        )
    )

Results:

[
    {
        "blockNumber": "3385",
        "timeStamp": "1598681758",
        "hash": "0xd638d39681335a703c9ed03d389c468e3ddaf74efbbc59f0be8b0217f1281df8",
        "nonce": "0",
        "blockHash": "0x51bdc4233991acedb25a895c8659f6fb7607dc40626a1dcb795e57ed7ed1a673",
        "transactionIndex": "1",
        "from": "0x35e7a025f4da968de7e4d7e4004197917f4070f1",
        "to": "0x0000000000000000000000000000000000001002",
        "value": "207350625000000",
        "gas": "9223372036854775807",
        "gasPrice": "0",
        "isError": "0",
        "txreceipt_status": "1",
        "input": "0x",
        "contractAddress": "",
        "cumulativeGasUsed": "112103",
        "gasUsed": "1516",
        "confirmations": "7581257"
    },

    ...
]
static get_normal_txs_by_address_paginated(address: str, page: int, offset: int, startblock: int, endblock: int, sort: str)

Get a list of all normal transactions for an address as numbered pages.

Parameters
  • address (str) – Target address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

  • startblock (int) – Start block of the query.

  • endblock (int) – End block of the query.

  • sort (str) – “asc” to return results in ascending order.

Returns

All transactions on requested page as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_normal_txs_by_address_paginated(
            address="0x35e7a025f4da968de7e4d7e4004197917f4070f1",
            startblock=0,
            endblock=99999999,
            page=1,
            offset=10,
            sort="asc",
        )
    )

Results:

[
    {
        "blockNumber": "3385",
        "timeStamp": "1598681758",
        "hash": "0xd638d39681335a703c9ed03d389c468e3ddaf74efbbc59f0be8b0217f1281df8",
        "nonce": "0",
        "blockHash": "0x51bdc4233991acedb25a895c8659f6fb7607dc40626a1dcb795e57ed7ed1a673",
        "transactionIndex": "1",
        "from": "0x35e7a025f4da968de7e4d7e4004197917f4070f1",
        "to": "0x0000000000000000000000000000000000001002",
        "value": "207350625000000",
        "gas": "9223372036854775807",
        "gasPrice": "0",
        "isError": "0",
        "txreceipt_status": "1",
        "input": "0x",
        "contractAddress": "",
        "cumulativeGasUsed": "112103",
        "gasUsed": "1516",
        "confirmations": "7581258"
    },

    ...
]
static get_validated_blocks_by_address(address: str)

Get a list of validated blocks by a specific address.

Parameters

address (str) – Target validator address.

Returns

All validated blocks as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_validated_blocks_by_address(
            address="0x4396e28197653d0c244d95f8c1e57da902a72b4e"
        )
    )

Results:

[
    {
        "blockNumber": "5572207",
        "timeStamp": "1615421320",
        "blockReward": "82705403500220352"
    },
    {
        "blockNumber": "5572186",
        "timeStamp": "1615421257",
        "blockReward": "86981148000000000"
    },

    ...
]
static get_validated_blocks_by_address_paginated(address: str, page: int, offset: int)

Get a list of validated blocks by a specific address as numbered pages.

Parameters
  • address (str) – Target validator address.

  • page (int) – Page number to fetch.

  • offset (int) – Max records to return.

Returns

All validated blocks as list of dictionaries per page.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_validated_blocks_by_address_paginated(
            address="0x4396e28197653d0c244d95f8c1e57da902a72b4e",
            page=1,
            offset=100
        )
    )

Results:

[
    {
    "blockNumber": "5572207",
    "timeStamp": "1615421320",
    "blockReward": "82705403500220352"
    },

    ...
]

bscscan.modules.blocks module

class bscscan.modules.blocks.Blocks

Bases: object

static get_block_number_by_timestamp(timestamp: int, closest: str)

Get block number given a specific timestamp.

NOTE: Supports UNIX timestamps in seconds.

Parameters
  • timestamp (int) – Target timestamp.

  • closest (str) – Closest block “before” or “after” target timestamp.

Returns

Block number for requested timestamp.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_block_number_by_timestamp(
            timestamp="1601510400",
            closest="before"
        )
    )

Results:

"946206"
static get_block_reward_by_block_number(block_no: int)

Get block reward by block number.

Parameters

block_no (int) – Target block number.

Returns

Block reward as a dictionary of various data.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_block_reward_by_block_number(
            block_no="2150000"
        )
    )

Results:

{
    "blockNumber": "2150000",
    "timeStamp": "1605122780",
    "blockMiner": "0xee01c3b1283aa067c58eab4709f85e99d46de5fe",
    "blockReward": "12141249999983048",
    "uncles": [],
    "uncleInclusionReward": "0"
}
static get_est_block_countdown_time_by_block_number(block_no: int)

Get estimated countdown time for a given block.

Parameters

block_no (int) – Target block number.

Returns

Countdown time in a dictionary of various data.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_est_block_countdown_time_by_block_number(
            block_no="8000000"
        )
    )

Results:

{
    "CurrentBlock": "7584646",
    "CountdownBlock": "8000000",
    "RemainingBlock": "415354",
    "EstimateTimeInSec": "1246077.0"
}

bscscan.modules.contracts module

class bscscan.modules.contracts.Contracts

Bases: object

static get_contract_abi(contract_address: str)

Get ABI for a specific contract, if uploaded.

Parameters

contract_address (str) – Target contract address.

Returns

ABI as a string.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_contract_abi(
            address="0x0000000000000000000000000000000000001004"
        )
    )

Results:

"[{'inputs':[],'stateMutability':'nonpayable','type':'constructor'}, ...]"
static get_contract_source_code(contract_address: str)

Get source code for a specific contract, if uploaded.

Parameters

contract_address (str) – Target contract address.

Returns

Source code in a list of dictionaries of various data.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_contract_source_code(
            address="0x0000000000000000000000000000000000001004"
        )
    )

Results:

[
    {
        "SourceCode": "// File: contracts/interface/IBEP20.sol\r\n\r\npragma...",
        "ABI": "[{'inputs':[],'stateMutability':'nonpayable',...}]",
        "ContractName": "TokenHub",
        "CompilerVersion": "v0.6.4+commit.1dca32f3",
        "OptimizationUsed": "1",
        "Runs": "200",
        "ConstructorArguments": "",
        "EVMVersion": "Default",
        "Library": "",
        "LicenseType": "None",
        "Proxy": "0",
        "Implementation": "",
        "SwarmSource": "ipfs://cf38311fc70c7842415f6e43694ca6a2795a904f0541302504db82e7675343ff"
    }
]

bscscan.modules.logs module

class bscscan.modules.logs.Logs

Bases: object

static get_logs(from_block: int, to_block: int, address: str, topic_0: str = '', topic_1: str = '', topic_2: str = '', topic_3: str = '', topic_0_1_opr: str = '', topic_1_2_opr: str = '', topic_2_3_opr: str = '', topic_0_2_opr: str = '', topic_0_3_opr: str = '', topic_1_3_opr: str = '')

This is an alternative to the native eth_getLogs. An address and/or topic_x parameters are required. When multiple topic_x parameters are used, the topic_x_y_opr (“and”/”or” operator) is also required.

NOTE: Only the first 1000 results are returned.

Parameters
  • from_block (int) – Start block of the query.

  • to_block (int) – End block of the query.

  • address (str) – Address of the logs.

  • topic_0 (str, optional) – Topic 0 in the logs. Defaults to “”.

  • topic_1 (str, optional) – Topic 1 in the logs. Defaults to “”.

  • topic_2 (str, optional) – Topic 2 in the logs. Defaults to “”.

  • topic_3 (str, optional) – Topic 3 in the logs. Defaults to “”.

  • topic_0_1_opr (str, optional) – Logical operator between topic 0 and 1. Defaults to “”.

  • topic_1_2_opr (str, optional) – Logical operator between topic 1 and 2. Defaults to “”.

  • topic_2_3_opr (str, optional) – Logical operator between topic 2 and 3. Defaults to “”.

  • topic_0_2_opr (str, optional) – Logical operator between topic 0 and 2. Defaults to “”.

  • topic_0_3_opr (str, optional) – Logical operator between topic 0 and 3. Defaults to “”.

  • topic_1_3_opr (str, optional) – Logical operator between topic 1 and 3. Defaults to “”.

Returns

The event logs in a dictionary, including topics and data fields.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_logs(
            from_block=4993830,
            to_block=4993832,
            address="0xe561479bebee0e606c19bb1973fc4761613e3c42",
            topic_0="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
            topic_0_1_opr="and",
            topic_1="0x000000000000000000000000730e2065b9daee84c3003c05bf6d2b3a08e55667"
        )
    )

Results:

[
    {
    "address": "0xe561479bebee0e606c19bb1973fc4761613e3c42",
    "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "0x000000000000000000000000730e2065b9daee84c3003c05bf6d2b3a08e55667",
        "0x000000000000000000000000d7d19938eae260d7f0e0a4c36e665ff4cf4b7acc"
    ],
    "data": "0x000000000000000000000000000000000000000000000000076cd96f53f24b0a",
    "blockNumber": "0x4c3326",
    "timeStamp": "0x602e9ef1",
    "gasPrice": "0x2540be400",
    "gasUsed": "0x1b0f2",
    "logIndex": "0xf7",
    "transactionHash": "0x73844fcfc6beab2e973a897c9573f4d79811b12213ce263045a203e0d3cea90e",
    "transactionIndex": "0xb9"
    }
]

bscscan.modules.proxy module

class bscscan.modules.proxy.Proxy

Bases: object

static get_proxy_block_by_number(tag: str)

Get information about a block by its block number.

Parameters

tag (str) – The target block tag.

Returns

Information about target block, including its transactions.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_block_by_number(
            tag="0x3d0900"
        )
    )

Results:

{
    "difficulty": "0x2",
    "extraData": "0xd883010004846765746888676f312e31352e35856c696e7578000000000000000bac492386862ad3df4b666bc096b0505bb694da22b81f8e175ffde54d797fe11eb03f9e3bf75f1d2d4c407bbe49438ed859fe965b140dcf1aab71a935e7a025f4da968de7e4d7e4004197917f4070f14430b3230294d12c6ab2aac5c2cd68e80b16b5816488aa4d1955ee33403f8ccb1d4de5fb97c7ade2685b1ded8013785d6623cc18d214320b6bb6475968bf0b8b6fb4e317a0f9d6f03eaf8ce6675bc60d6bbad7cf34b5fa511d8e963dbba288b1960e75d672b61c6014342d914470ec7ac2975be345796c2b7ae2f5b9e386cd1b50a4550696d957cb4900f03a82012708dafc9e1b880fd083b32182b869be8e098c4d90829ce8f72d0163c1d5cf348a862d550630a34efe6222e33adb84307f41b218d1823afb6f6da6f79b60359f141df90a0c745125b131caaffd12ada8c942f31098482748fcf2b9d3dc1d8de7b0e4b218c5d6af1f979ac42bc68d98a5a0d796c6ab01b8f7166496996a7da21cf1f1b04d9b3e26a3d077ce2fd7544e0b2cc94692d4a704debef7bcb61328d6caa02bbebaebb5d7e581e4b66559e635f805ffea0a6e3c511bbd10f4519ece37dc24887e11b55deee8583c06155b4bcae968b057a7b9fc104d05245ea6768867bb02fc189e81391de2c3e7f8b9a9f48a4a0c562ab81f4b2221f9c761d3dff0f17f08f1e0259e5f00",
    "gasLimit": "0x1c9c380",
    "gasUsed": "0x119964",
    "hash": "0x3a21da1d1f88577771f1e94b554294d699f696487a3554c1618521d68b48a493",
    "logsBloom": "0x0520040200006004000100008400402080000840048000000000000088a0010000080000000000100000020000080000080000200008000000000000002420000010008000004002000000080010102120100000101400024a04000000100080000000240242000002000040008008000000001201880200000000100020000800400010000000040030000000000000000c0c010000800930040040000008300600000000400004004000020004000000004000000000009000000000000004000100020000002000000002041208000000000000000012380002010000e0002810040000000000012000000001000000040008400808000000000000000000",
    "miner": "0x4430b3230294d12c6ab2aac5c2cd68e80b16b581",
    "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "nonce": "0x0000000000000000",
    "number": "0x3d0900",
    "parentHash": "0x911a33c1adbba5b5af70aa3d6adcc76edb23ba0da1b38948b2ca0de4a8ac770c",
    "receiptsRoot": "0xfc2c03091df8019b78ef2c6eb6c0013c9ccd635aa8a5bccb33022c18b15b6c08",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x8c4",
    "stateRoot": "0xad1d6884d20fca931c9ba5d1a62cd65aaf1bceeb56c30180cee218be18e42393",
    "timestamp": "0x60010570",
    "totalDifficulty": "0x7a0149",
    "transactions": [
        {
            "blockHash": "0x3a21da1d1f88577771f1e94b554294d699f696487a3554c1618521d68b48a493",
            "blockNumber": "0x3d0900",
            "from": "0xc524faaed591471a0b5fc93288fd8fe6f45d7b64",
            "gas": "0xf4240",
            "gasPrice": "0x4a817c800",
            "hash": "0x7d3a58fe7c29bd30b64928b3f05c14f42086abe78ed51420a3a11fb4253f3ab5",
            "input": "0x19efa3b90000000000000000000000008e78c72b37ce47811901ac99ded5c62277d2e18758275c2ad36555c03255212657dfae202219de57225d31c60be54b3c05717c41",
            "nonce": "0x31206",
            "to": "0x3900afd6613022d8e37a9ba945e02ee920bc48dc",
            "transactionIndex": "0x0",
            "value": "0x0",
            "v": "0x94",
            "r": "0xd6a7a7eef0023721c580cb05802293433fb9c08614a9606d2a2139943bc4498",
            "s": "0x625f62272dfb849c08cd47f5f008421502caf87c508885c7d6c853f73989253f"
        },

        ...
    ]
    "transactionsRoot": "0x8ad23ac4ccf6e9335e7801c5ebbd5f4546413cca56ab2ace02beaa022415c236",
    "uncles": []
}
static get_proxy_block_number()

Get the number of the most recent block.

Returns

The block number.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(await client.get_proxy_block_number())

Results:

"0x73fe1b"
static get_proxy_block_transaction_count_by_number(tag: str)

Get the number of transactions in a specific block.

Parameters

tag (str) – The target block tag.

Returns

The number of txs in the block using hex base format.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_block_transaction_count_by_number(
            tag="0x3d0900"
        )
    )

Results:

"0x7"
static get_proxy_call(to: str, data: str)

Executes a new message call immediately without creating a transaction on the block chain.

Parameters
  • to (str) – Contract address to send message to.

  • data (str) – Message data in bytecode.

Returns

The response to the message in hex base format.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_call(
            to="0xAEEF46DB4855E25702F8237E8f403FddcaF931C0",
            data="0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724"
        )
    )

Results:

"0x"
static get_proxy_code_at(address: str)

Get contract bytecode at target address, if any.

Parameters

address (str) – Address to query for bytecode.

Returns

The bytecode in hex base format.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_code_at(
            address="0x0000000000000000000000000000000000001000"
        )
    )

Results:

"0x60806040526004361061027d5760003560e01c80639dc092621161014f578..."
static get_proxy_est_gas(from_addr: str, to_addr: str, data: str, value: str, gas_price: str, gas: str)

Get gas estimate by making a dummy call/transaction that is not added to the blockchain and returns the hypothetically used gas.

Parameters
  • from_addr (str) – Sender of transaction.

  • to_addr (str) – Receiver of transaction.

  • data (str) – Data of transaction.

  • value (str) – Value of transaction.

  • gas_price (str) – Gas price of transaction.

  • gas (str) – Gas of transaction.

Returns

Estimated used gas for transaction.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_est_gas(
            data="0x4e71d92d",
            from_addr="0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
            to_addr="0xf0160428a8552ac9bb7e050d90eeade4ddd52843",
            value="0xff22",
            gas_price="0x51da038cc",
            gas="0x5f5e0ff"
        )
    )

Results:

"0x5248"
static get_proxy_gas_price()

Get current gas price in wei.

Returns

Gas price in wei and hex base format.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(await client.get_proxy_gas_price())

Results:

"0x12a05f200"
static get_proxy_storage_position_at(position: str, address: str)

Get the value from a storage position at a given address.

Parameters
  • position (str) – Target position in hex base format.

  • address (str) – Target address.

Returns

Value in hex base format.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_storage_position_at(
            position="0x0",
            address="0x0000000000000000000000000000000000001004"
        )
    )

Results:

"0x0000000000000000000000000000000000000000000000000000000000000001"
static get_proxy_transaction_by_block_number_and_index(tag: str, index: str)

Get transaction by block number and tx index.

Parameters
  • tag (str) – Target block tag.

  • index (str) – Target tx index.

Returns

Standard tx data, including v,r,s values.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_transaction_by_block_number_and_index(
            tag="0x3d0900",
            index"="0x0"
        )
    )

Results:

{
    "blockHash": "0x3a21da1d1f88577771f1e94b554294d699f696487a3554c1618521d68b48a493",
    "blockNumber": "0x3d0900",
    "from": "0xc524faaed591471a0b5fc93288fd8fe6f45d7b64",
    "gas": "0xf4240",
    "gasPrice": "0x4a817c800",
    "hash": "0x7d3a58fe7c29bd30b64928b3f05c14f42086abe78ed51420a3a11fb4253f3ab5",
    "input": "0x19efa3b90000000000000000000000008e78c72b37ce47811901ac99ded5c62277d2e18758275c2ad36555c03255212657dfae202219de57225d31c60be54b3c05717c41",
    "nonce": "0x31206",
    "to": "0x3900afd6613022d8e37a9ba945e02ee920bc48dc",
    "transactionIndex": "0x0",
    "value": "0x0",
    "v": "0x94",
    "r": "0xd6a7a7eef0023721c580cb05802293433fb9c08614a9606d2a2139943bc4498",
    "s": "0x625f62272dfb849c08cd47f5f008421502caf87c508885c7d6c853f73989253f"
}
static get_proxy_transaction_by_hash(txhash: str)

Get tx information given its hash.

Parameters

txhash (str) – Target transaction hash.

Returns

Standard tx data, including v,r,s values.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_transaction_by_hash(
            txhash="0xa0f2e87dfb75e3ebb8b23eff7b490442ff74cf8921eb61217dfc48918fe4020f"
        )
    )

Results:

{
    "blockHash": "0x3a21da1d1f88577771f1e94b554294d699f696487a3554c1618521d68b48a493",
    "blockNumber": "0x3d0900",
    "from": "0x4430b3230294d12c6ab2aac5c2cd68e80b16b581",
    "gas": "0x7fffffffffffffff",
    "gasPrice": "0x0",
    "hash": "0xa0f2e87dfb75e3ebb8b23eff7b490442ff74cf8921eb61217dfc48918fe4020f",
    "input": "0xf340fa010000000000000000000000004430b3230294d12c6ab2aac5c2cd68e80b16b581",
    "nonce": "0x278d1",
    "to": "0x0000000000000000000000000000000000001000",
    "transactionIndex": "0x6",
    "value": "0x50bbe73ea9b000",
    "v": "0x93",
    "r": "0x4e63792b339521b74cdb3cad2d8fdf0f5fc3dbb2e169a5a536692dd89eca4da1",
    "s": "0x40f8ccd64337d6cfb15f1d40932068356da34138b8c9f6a818a68d20607451dc"
}
static get_proxy_transaction_count(address: str)

Get number of transactions sent from an address.

Parameters

address (str) – Target address.

Returns

Number of txs using hex base format.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_transaction_count(
            address="0x4430b3230294D12c6AB2aAC5C2cd68E80B16b581"
        )
    )

Results:

"0x56adb"
static get_proxy_transaction_receipt(txhash: str)

Get receipt of transaction from its hash.

Parameters

txhash (str) – Target transaction hash.

Returns

Transaction receipt including logs.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_proxy_transaction_receipt(
            txhash="0xa0f2e87dfb75e3ebb8b23eff7b490442ff74cf8921eb61217dfc48918fe4020f"
        )
    )

Results:

{
    "blockHash": "0x3a21da1d1f88577771f1e94b554294d699f696487a3554c1618521d68b48a493",
    "blockNumber": "0x3d0900",
    "contractAddress": null,
    "cumulativeGasUsed": "0x119964",
    "from": "0x4430b3230294d12c6ab2aac5c2cd68e80b16b581",
    "gasUsed": "0x42fe",
    "logs": [
    {
        "address": "0x0000000000000000000000000000000000001000",
        "topics": [
        "0x93a090ecc682c002995fad3c85b30c5651d7fd29b0be5da9d784a3302aedc055",
        "0x0000000000000000000000004430b3230294d12c6ab2aac5c2cd68e80b16b581"
        ],
        "data": "0x0000000000000000000000000000000000000000000000000050bbe73ea9b000",
        "blockNumber": "0x3d0900",
        "transactionHash": "0xa0f2e87dfb75e3ebb8b23eff7b490442ff74cf8921eb61217dfc48918fe4020f",
        "transactionIndex": "0x6",
        "blockHash": "0x3a21da1d1f88577771f1e94b554294d699f696487a3554c1618521d68b48a493",
        "logIndex": "0x1f",
        "removed": false
    }
    ],
    "logsBloom": "0x00000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002010000000000000000000000000000000000020000200000000000000800000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000",
    "status": "0x1",
    "to": "0x0000000000000000000000000000000000001000",
    "transactionHash": "0xa0f2e87dfb75e3ebb8b23eff7b490442ff74cf8921eb61217dfc48918fe4020f",
    "transactionIndex": "0x6"
}

bscscan.modules.stats module

class bscscan.modules.stats.Stats

Bases: object

static get_bnb_last_price()

Get the last price of BNB against BTC and USD.

Returns

Latest dictionary of BNB price pairs.

Return type

dict

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(await client.get_bnb_last_price())

Results:

{
    "ethbtc": "0.00927",
    "ethbtc_timestamp": "1621600148",
    "ethusd": "379.15",
    "ethusd_timestamp": "1621600183"
}
static get_total_bnb_supply()

Get total supply of BNB on Binance Smart Chain.

Returns

The total supply of BNB.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(await client.get_total_bnb_supply())

Results:

"17673568869449800000000000"
static get_validators_list()

Get list of validators on Binance Smart Chain.

Returns

All validators as a list of dictionaries.

Return type

List[dict]

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(await client.get_validators_list())

Results:

[
    {
        "validatorAddress": "0x9f8ccdafcc39f3c7d6ebf637c9151673cbc36b88",
        "validatorName": "",
        "validatorStatus": "0",
        "validatorVotingPower": "43379676392570",
        "validatorVotingPowerProportion": "0.0617"
    },
    {
        "validatorAddress": "0x2465176c461afb316ebc773c61faee85a6515daa",
        "validatorName": "",
        "validatorStatus": "0",
        "validatorVotingPower": "38039845465042",
        "validatorVotingPowerProportion": "0.0541"
    },

    ...
]

bscscan.modules.tokens module

class bscscan.modules.tokens.Tokens

Bases: object

static get_acc_balance_by_token_contract_address(contract_address: str, address: str)

Get account balance given a contract address.

Parameters
  • contract_address (str) – Target contract address.

  • address (str) – Target wallet address.

Returns

The target token balance of target account.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_acc_balance_by_token_contract_address(
            contract_address="0xe9e7cea3dedca5984780bafc599bd69add087d56",
            address="0x89e73303049ee32919903c09e8de5629b84f59eb"
        )
    )

Results:

"0"
static get_circulating_supply_by_contract_address(contract_address: str)

Get circulating supply of token by its contract address.

Parameters

contract_address (str) – Target contract address.

Returns

Circulating supply of token behind target contract.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_circulating_supply_by_contract_address(
            contract_address="0xe9e7cea3dedca5984780bafc599bd69add087d56"
        )
    )

Results:

"4086900168016026430118545633"
static get_total_supply_by_contract_address(contract_address: str)

Get total supply of token by its contract address.

Parameters

contract_address (str) – Target contract address.

Returns

Total supply of token behind target contract.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_total_supply_by_contract_address(
                contract_address="0xe9e7cea3dedca5984780bafc599bd69add087d56"
            )
    )

Results:

"4200999999996203280118545633"

bscscan.modules.transactions module

class bscscan.modules.transactions.Transactions

Bases: object

static get_tx_receipt_status(txhash: str)

Check the status of a transaction receipt.

Parameters

txhash (str) – Target tx hash.

Returns

The status code.

Return type

str

Example:

from bscscan import BscScan

async with BscScan(YOUR_API_KEY) as client:
    print(
        await client.get_tx_receipt_status(
            txhash="0xe9975702518c79caf81d5da65dea689dcac701fcdd063f848d4f03c85392fd00"
            )
        )

Results:

"1"

Module contents