Giter Site home page Giter Site logo

pcko1 / bscscan-python Goto Github PK

View Code? Open in Web Editor NEW
288.0 8.0 104.0 17.66 MB

The most popular asynchronous Python API for BscScan (Binance Smart Chain Explorer), available via PyPI.

Home Page: https://bscscan-python.pankotsias.com/

License: MIT License

Python 99.78% Shell 0.22%
binance binance-smart-chain python blockchain blockchain-explorer bsc asyncio

bscscan-python's Introduction

bscscan-python

A complete Python API for BscScan.com

Powered by BscScan.com APIs

Available on PyPI

๐Ÿ“– Read the official documentation here ๐Ÿ“–

๐Ÿ‘‡

A fork of the etherscan-python package.

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'

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}
}

Feel free to leave a โญ if you found this package useful.


Powered by Bscscan.com APIs.

bscscan-python's People

Contributors

codacy-badger avatar deepsource-autofix[bot] avatar deepsourcebot avatar eggpool avatar pcko1 avatar phe-sto avatar valkorian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bscscan-python's Issues

[BUG] Circular import error

Describe the bug
A clear and concise description of what the bug is.

Upon installing either via PyPI or git (master or stable branch) using pipenv the "from bscscan import BscScan" import fails with "ImportError: cannot import name 'BscScan' from partially initialized module 'bscscan' (most likely due to a circular import)". I am using python 3.8.10.

To Reproduce
In order to assist you with your problem, we need a minimal code snippet that replicates the bug. Avoid disclosing your API keys.

Steps to reproduce the behavior:

  1. Run "pipenv install bscscan-python"
  2. Create script with single line from bscscan import BscScan as suggested from the docs
  3. Run script and get error

Expected behavior
A clear and concise description of what you expected to happen.

The import should work based on the documentation.

Screenshots
If applicable, add screenshots to help explain your problem.

N/A

System info (please complete the following information):

  • OS and version: macOS 11.13.1
  • Python version: 3.8.10
  • bscscan-python version: 2.0.0

Additional context
Add any other context about the problem here.

How do I get the implementation contract address from the proxy contract address?

Could you help us with this question? Basically we want to interact properly with a proxy contract

https://ethereum.stackexchange.com/questions/103143/how-do-i-get-the-implementation-contract-address-from-the-proxy-contract-address

Details as followed:

I'm using web3.py to interact with multiple unknown contracts, where I don't know beforehand if a contract is a proxy contract or the actual contract. I'm getting the ABIs for the contracts on-the-fly from BSCScan's API. Assume I am only interested in contracts whose ABIs are available on BSCscan.

When I retrieve the ABI of a contract from BSCScan, sometimes the ABI has functions like
['admin', 'changeAdmin', 'implementation', 'upgradeTo', 'upgradeToAndCall'] which is how I understand it's a proxy contract address.

Now I'd like to get the address of the implementation contract from the proxy contract. The final goal is to get the ABI of the implementation contract via BSCScan, for which I need the address of the implementation contract.

How do I get the ABI (or the address) of the implementation contract?

(While I am using BSCScan and BSC, for the purposes of this answer I assume the answer for Ethereum and Etherscan is the same)

from bscscan import BscScan
from web3 import Web3

contract_address = '0x88f1A5ae2A3BF98AEAF342D26B30a79438c9142e'  # Test case


def get_abi(contract_address):
    with BscScan(api_key, asynchronous=False) as client:
        abi_string = client.get_contract_abi(contract_address)
    return abi_string


web3 = Web3(Web3.HTTPProvider(bsc))
abi_string = get_abi(address)
contract = web3.eth.contract(address=address, abi=abi_string)
if 'implementation' in [foo.function_identifier for foo in contract.all_functions()]:
    # it's a proxy contract as its ABI contained implementation()
    implementation_address = contract.functions.implementation().call()  # <-- Error
    implementation_abi_string = get_abi(implementation_address)
    contract = web3.eth.contract(address=address, abi=implementation_abi_string)


desired_result = contract.functions.somefunction().call()

This results in

Traceback (most recent call last):
  ...
  File "helpers.py", line 86, in create_contract_object
    implementation_address = contract.functions.implementation().call()
  File "/venv-mac-py/lib/python3.9/site-packages/web3/contract.py", line 957, in call
    return call_contract_function(
  File "/venv-mac-py/lib/python3.9/site-packages/web3/contract.py", line 1501, in call_contract_function
    return_data = web3.eth.call(
  File "/venv-mac-py/lib/python3.9/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str, params, error_formatters)
  File "/venv-mac-py/lib/python3.9/site-packages/web3/manager.py", line 159, in request_blocking
    apply_error_formatters(error_formatters, response)
  File "/venv-mac-py/lib/python3.9/site-packages/web3/manager.py", line 63, in apply_error_formatters
    formatted_response = pipe(response, error_formatters)
  File "cytoolz/functoolz.pyx", line 667, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 642, in cytoolz.functoolz.c_pipe
  File "/venv-mac-py/lib/python3.9/site-packages/web3/_utils/method_formatters.py", line 544, in raise_solidity_error_on_revert
    raise ContractLogicError('execution reverted')
web3.exceptions.ContractLogicError: execution reverted

AssertionError [ ] -- No transactions found <--- is this a bug ?

Hi. I am having , for another BSC address, thrown the following exception :

......./lib/python3.9/site-packages/bscscan/bscscan.py", line 33, in wrapper
return parser.parse(r)
......./lib/python3.9/site-packages/bscscan/utils/parsing.py", line 12, in parse
assert status, f"{result} -- {message}"
AssertionError: [] -- No transactions found

Is it expected to throw an error , opposite just returning nothing ?

Thank you. Ionut.

How to show decimal place?[bsc.get_bnb_balance]

Almost certain this issue is with me, and not the API.
Why is the decimal place not displaying when I use

bsc.get_bnb_balance(address="0x0000000000000000000000000000000000001004")

'167195709084498025431541166'

I'm a noob....

UNABLE TO GET FULL TOKEN BALANCE FOR A GIVING ADDRESS

Hello devs, first of all my pleasure for your great work. I have a small issue with your module. I want to get the full token balance for a giving address, as you can see on this etherscan url (https://www.bscscan.com/tokenholdings?a=0xFAe2dac0686f0e543704345aEBBe0AEcab4EDA3d) but I didn't find out it on your documentation. Anyone of you can please help me?
Would be great if you can show me a full working example code.
If you don't provide this function, please considering of doing it because would be great. Thanks for attention and hv a nice day

get_logs() Doesn't return all of the possible transaction and stops mid-way.

Describe the bug
The get_Logs() function does not return all the possible transaction that matches the filter arguments handed to it.

To Reproduce
In order to assist you with your problem, we need a minimal code snippet that replicates the bug. Avoid disclosing your API keys.

async with BscScan(API_KEY) as client:
        #try:
        code = await client.get_logs(
        from_block="desired-start-block",
        to_block="desired-end-block",
        address ="address-of-desired-ca",
        topic_0 = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        topic_0_2_opr="and",
        topic_2="desired-address"

        )```

Steps to reproduce the behavior:

1.  Create a request for get_logs
2. Hand it a topic_0 for a transfer event
3. give it a topic 2 of a certain CA
4. Print the results

**Expected behavior**
I tried this command on a coin with 14,000 transaction and I was only able to retrieve the first 1,000 transaction before it quit. I cannot tell if this is an error on my side or due to the API's problem.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**System info (please complete the following information):**
 - OS and version: [e.g. Mac Catalina OS]
 - Python version: [e.g. `3.8.2`]
 - `bscscan-python` version: [e.g. `2.0.0`]

**Additional context**
Add any other context about the problem here.

[FEATURE]

Have you checked the documentation of this package?
โ˜‘๏ธ [Yes/No]

Is the feature on BscScan.com but missing from this package?
โ˜‘๏ธ [Yes/No]
---> If yes, please add a link to the missing feature.

Is your feature request related to a problem? Please describe.
โ˜‘๏ธ A clear and concise description of what the problem is, if any.

Describe the solution you'd like
โ˜‘๏ธ A clear and concise description of what you want to happen.

Describe alternatives you've considered
โ˜‘๏ธ A clear and concise description of any alternative solutions or features you've considered.

Additional context
โ˜‘๏ธ Add any other context or screenshots about the feature request here.

[FEATURE]/quesiton (help)

Is any way to get all the transactions info from a block with the block nยบ?
i'm searching the way to get all the transactions info from a block and i didn't found it. if you know how to get that info pleas help me.
thanks

Getting nested transactions [BUG]

Hello,

So I'm trying to track transactions of a specific token in a wallet, and get the amount of BNB exchanged for the amount of the token.

Let's say I am using get_bep20_token_transfer_events_by_address_and_contract_paginated to get a list of transactions of a specific token in a wallet. The amount of token for each transaction is there. I then feed each transaction hash into get_internal_txs_by_txhash go find the amount of BNB swapped for each transaction.

I am having issues when a transaction is in fact a token to token swap, instead of a straightforward BNB to token swap.
get_internal_txs_by_txhash returns an error AssertionError: [] -- No transactions found.

As you can see, this transactions has nested transactions. I would like to retrieve the BNB transaction out of those.

I don't think this is an issue with your code, because BSCscan's url API yields the same results
https://api.bscscan.com/api?module=account&action=txlistinternal&txhash=0x09f674d2a732c6359ffabaafc995b63a6f522243c4086b0ee080101a92d4a134&apikey=YourApiKeyToken

If I understand correctly, Internal Transaction are done by the contract the wallet is interacting with. And indeed, there are no contract transactions in this specific transaction.

Do you have any other recommendation on how to obtain the amount of BNB swapped in this transaction?

Thanks!

[FEATURE]

Have you checked the documentation of this package?
โ˜‘๏ธ [Yes/No]

Is the feature on BscScan.com but missing from this package?
โ˜‘๏ธ [Yes/No]
---> If yes, please add a link to the missing feature.

Is your feature request related to a problem? Please describe.
โ˜‘๏ธ A clear and concise description of what the problem is, if any.

Describe the solution you'd like
โ˜‘๏ธ A clear and concise description of what you want to happen.

The Bscan docs state they support sending raw transactions. Would be nice if this library had this method https://docs.bscscan.com/api-endpoints/geth-parity-proxy#eth_sendrawtransaction

Describe alternatives you've considered
โ˜‘๏ธ A clear and concise description of any alternative solutions or features you've considered.

Additional context
โ˜‘๏ธ Add any other context or screenshots about the feature request here.

How to get the function called

Hello,

I'm trying to get more detail about a specific transaction, for example i would like to know the name of the function called on a particular transaction. Ex, on this transaction : https://bscscan.com/tx/0xc8df10eac2893ebdff2074b3141409b23f418b82c46217da9b6c69f335903600
image

I would like to know how can i retrieve that the function used is activateUserStaking()

Right now i tried with get_bep20_token_transfer_events_by_address, where i get a list of transaction, but the function called is not specifed. I also tried with get_internal_txs_by_txhash but i still don't have the name of function :

[{'blockNumber': '14914523', 'timeStamp': '1643837585', 'from': '0xf8303c3ac316b82bcbb34649e24616aa9ed9e5f4', 'to': '0x49d282fcdd774593d9da39636d6d40c626637466', 'value': '20000000000000000', 'contractAddress': '', 'input': '', 'type': 'call', 'gas': '296473', 'gasUsed': '278828', 'isError': '0', 'errCode': ''}, {'blockNumber': '14914523', 'timeStamp': '1643837585', 'from': '0x49d282fcdd774593d9da39636d6d40c626637466', 'to': '0x958f7322dad103ca64ee7914ade761bdebbb7656', 'value': '20000000000000000', 'contractAddress': '', 'input': '', 'type': 'call', 'gas': '282708', 'gasUsed': '269379', 'isError': '0', 'errCode': ''}, {'blockNumber': '14914523', 'timeStamp': '1643837585', 'from': '0x958f7322dad103ca64ee7914ade761bdebbb7656', 'to': '0x87b1acce6a1958e522233a737313c086551a5c76', 'value': '20000000000000000', 'contractAddress': '', 'input': '', 'type': 'call', 'gas': '252031', 'gasUsed': '85607', 'isError': '0', 'errCode': ''}]

I think i'm missing something, someone can help me please ?

how to figure out the number of decimals?

Using the method get_acc_balance_by_token_contract_address(contract_address=value, address=my_address) to get the token balance for an address, the output does not take into account the number of decimals. For example:
fetching MARSCAT (contract address 0xd31bad66aefa525b808ee569a514f6345b0bea2d) token balance returns a number is exact (no decimals):

Result: {"status":"1","message":"OK","result":"20"} --> actual value = 20

But for many other tokens, it needs to be divided by 1e+18:
For example, for "ANYTOKEN" (contract address 0xF68C9Df95a18B2A5a5fa1124d79EEEffBaD0B6Fa):

Result: {"status":"1","message":"OK","result":"1000000000000000000"} --> actual value = 1

Question is how can we know the divisor / i.e. how many decimals is in the result?

Add Contract Address to get_bep20_token_transfer_events_by_address

Have you checked the documentation of this package?
โ˜‘๏ธ [Yes]

Is the feature on BscScan.com but missing from this package?
โ˜‘๏ธ [Yes]
---> If yes, please add a link to the missing feature.
https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-bep-20-token-transfer-events-by-address
with optional Contract Address.

Is your feature request related to a problem? Please describe.
โ˜‘๏ธ A clear and concise description of what the problem is, if any.
I am trying to get the Transactions for a Wallet, by Contract , between two Block addresses, to help with some analytics.

Describe the solution you'd like
โ˜‘๏ธ A clear and concise description of what you want to happen.
Add contract_address as a parameter , as show in example below.
await client.get_bep20_token_transfer_events_by_address(
contract_address=CON_ADDR,
address=wallet,
startblock=start,
endblock=end,
sort="asc"
)

Describe alternatives you've considered
โ˜‘๏ธ A clear and concise description of any alternative solutions or features you've considered.
I already have this in Google Script but cant see this in the BScSCAN Python module. I've looked at some complex processing, but would just be alot more complex than adding contract address to the Api call.

Additional context
โ˜‘๏ธ Add any other context or screenshots about the feature request here.
Could it work by having just one call to get transactions for an address but defaults to All tokens if NO contract is specified, and block start 0, and block end 999999999 if blocks aren't set. eg
get_bep20_token_transfer_events( contract , wallet, startblock, endblock) using the _ for default
eg
get_bep20_token_transfer_events( _ , wallet, startblock, endblock) gets all transactions for a wallet between start and end.

get_bep20_token_transfer_events( _, wallet, _, _) would get all transactions.

get_bep20_token_transfer_events( contract , _, startblock, endblock) all transactions for a contract between block numbers.

BTW, Nicely implemented module!

[BUG] Trying to fetch internal txns yields AssertionError if there are no internal txns

Describe the bug
Trying to fetch internal txns yields AssertionError if there are no internal txns

To Reproduce
Fetch blocks which do not have internal txns for a given account

Expected behavior
Return of an empty list. The docs said that the functions returns a list of dicts. So, if there are no txns I'd expect to return an empty list instead of yielding an error. Is that desired behaviour?

Additional context

Traceback (most recent call last):
  File "bscscan-import.py", line 190, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "bscscan-import.py", line 77, in main
    internal_txns = await bsc.get_internal_txs_by_address(
  File "~/lib/python3.9/site-packages/bscscan/core/async_client.py", line 27, in wrapper
    return parser.parse(await response.json())
  File "~/.local/lib/python3.9/site-packages/bscscan/utils/parsing.py", line 11, in parse
    assert status, f"{result} -- {message}"
AssertionError: [] -- No transactions found

Option to pass api endpoint explicitly (to support other chains)

Have you checked the documentation of this package?
โ˜‘๏ธ Yes

Is the feature on BscScan.com but missing from this package?
โ˜‘๏ธ No

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
I've hacked this to work for Polygon but it would be a nice to be able to pass in the url more explicitly.

from bscscan import BscScan
from bscscan.enums.fields_enum import FieldsEnum

ACCOUNT = "XXXXX"
POLYGON_API_KEY = "XXXXXXX"  # from here: https://polygonscan.com/apis
POLYGON_API_URL = "https://api.polygonscan.com/api?"

FieldsEnum.PREFIX = POLYGON_API_URL  # This is the hack
with BscScan(POLYGON_API_KEY, asynchronous=False) as poly_client:
    print(poly_client.get_bnb_balance(ACCOUNT))  # returns MATIC balance on Polygon chain

[FEATURE]/questioin

Have you checked the documentation of this package?
โ˜‘๏ธ [Yes/No]

Is the feature on BscScan.com but missing from this package?
โ˜‘๏ธ [Yes/No]
---> If yes, please add a link to the missing feature.

Is your feature request related to a problem? Please describe.
โ˜‘๏ธ A clear and concise description of what the problem is, if any.

Describe the solution you'd like
โ˜‘๏ธ A clear and concise description of what you want to happen.

Describe alternatives you've considered
โ˜‘๏ธ A clear and concise description of any alternative solutions or features you've considered.

Additional context
โ˜‘๏ธ Add any other context or screenshots about the feature request here.

'AsyncClient' object has no attribute 'get_bnb_balance'

from bscscan import BscScan
bsc = BscScan("MY_API") # key in quotation marks


ADR = "MY_ADR"

bsc.get_bnb_balance(address= ADR)

If i try to run this chunk i get this error:

"AttributeError: 'AsyncClient' object has no attribute 'get_bnb_balance'"

Does someone know where i made a mistake?

Thanks

SyntaxError: 'async with' outside async function

How do I fix this?
My code:

from bscscan import BscScan

async with BscScan('MY_API') as bsc:
    print(await bsc.get_bnb_balance(address="0x0000000000000000000000000000000000001004"))

results in:

SyntaxError: 'async with' outside async function

[BUG] ImportError: cannot import name 'resources'

Describe the bug
I've tried both installing from source and from pypi, and in both cases I get the following error:


ImportError Traceback (most recent call last)
in
1 import asyncio
----> 2 from bscscan import BscScan
3
4 YOUR_API_KEY = "U7IXASTYXEE7HYDWK1YU6G4AUR3Q45N1VX"
5 add_woop = "0xa70AEb15eE004d411E8ff303DCd8e706b664e018"

D:\Trabajo\Anaconda-python\envs\money_play\lib\site-packages\bscscan_init_.py in
----> 1 from .client import BscScan
2 from .modules.accounts import Accounts as accounts
3 from .modules.blocks import Blocks as blocks
4 from .modules.contracts import Contracts as contracts
5 from .modules.logs import Logs as logs

D:\Trabajo\Anaconda-python\envs\money_play\lib\site-packages\bscscan\client.py in
----> 1 from bscscan.core.async_client import AsyncClient
2 from bscscan.core.base import BaseClient
3 from bscscan.core.sync_client import SyncClient
4
5

D:\Trabajo\Anaconda-python\envs\money_play\lib\site-packages\bscscan\core\async_client.py in
1 import bscscan
2 from aiohttp import ClientSession
----> 3 from bscscan.core.base import BaseClient
4 from bscscan.enums.fields_enum import FieldsEnum as fields
5 from bscscan.utils.parsing import ResponseParser as parser

D:\Trabajo\Anaconda-python\envs\money_play\lib\site-packages\bscscan\core\base.py in
1 import json
----> 2 from importlib import resources
3
4 from bscscan import configs
5

ImportError: cannot import name 'resources'

To Reproduce
I'm just using the code in the Usage section of the github readme file.

Steps to reproduce the behavior:

  1. Install the library.
  2. Run the code provided in the Usage section in the github readme file.

Expected behavior
Get the bnb balance of the address.

System info (please complete the following information):

  • OS and version: Windows10
  • Python version: 3.6.12
  • bscscan-python version: 2.0.0

How to get value of a transaction?

Hello,

i'm using the API like that :
bsc.get_bep20_token_transfer_events_by_address(address=address, startblock=6910490, endblock=69104970, sort='desc')

i got this output:

[{'blockNumber': '6910497', 'timeStamp': '1619467957', 'hash': '0x93b68061d5c8c069f5b2f394c29594294b4c38aa5241fc39973832dae6ca2d6d', 'nonce': '412', 'blockHash': '0x666bc209d2ac157c9b706f2bd3fe960203d736e56cbe8038b9b2bf9939069050', 'from': '0x0a4259d2c647000d089c828b881970d85f823328', 'contractAddress': '0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03', 'to': '0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03', 'value': '14397341994138335', 'tokenName': 'TRYfinance', 'tokenSymbol': 'TRY', 'tokenDecimal': '18', 'transactionIndex': '67', 'gas': '469194', 'gasPrice': '5000000000', 'gasUsed': '298790', 'cumulativeGasUsed': '8286675', 'input': 'deprecated', 'confirmations': '566'}, {'blockNumber': '6910492', 'timeStamp': '1619467942', 'hash': '0x26801c3b2a527da7d15463ebddea21140ecc7fd90b19441463022d8c1775b5b4', 'nonce': '308', 'blockHash': '0xcb1b289f82e51c7a525eee956e1c958b7d7dd782aeb3cd64d1891e1fbfce342e', 'from': '0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03', 'contractAddress': '0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03', 'to': '0x28d02b415d2fca7d5a0fd91888289f950bb578a4', 'value': '9743471045495664476', 'tokenName': 'TRYfinance', 'tokenSymbol': 'TRY', 'tokenDecimal': '18', 'transactionIndex': '158', 'gas': '439386', 'gasPrice': '5000000000', 'gasUsed': '248918', 'cumulativeGasUsed': '26151924', 'input': 'deprecated', 'confirmations': '571'}, {'blockNumber': '6910492', 'timeStamp': '1619467942', 'hash': '0x26801c3b2a527da7d15463ebddea21140ecc7fd90b19441463022d8c1775b5b4', 'nonce': '308', 'blockHash': '0xcb1b289f82e51c7a525eee956e1c958b7d7dd782aeb3cd64d1891e1fbfce342e', 'from': '0x0a4259d2c647000d089c828b881970d85f823328', 'contractAddress': '0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03', 'to': '0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03', 'value': '49006688855056117', 'tokenName': 'TRYfinance', 'tokenSymbol': 'TRY', 'tokenDecimal': '18', 'transactionIndex': '158', 'gas': '439386', 'gasPrice': '5000000000', 'gasUsed': '248918', 'cumulativeGasUsed': '26151924', 'input': 'deprecated', 'confirmations': '571'}]

In the output i don't see any field "value" where i can get the amount of a transaction.
For example on this page :
https://bscscan.com/address/0xc12ecee46ed65d970ee5c899fcc7ae133aff9b03#tokentxns
I would like to get Value column of the table.

Do you know a way to do that please ?

SyncClient is owning NO attributes[BUG]

Describe the bug
SyncClient is not able to get any of the modules to work on.

To Reproduce

>>> dir(AsyncClient)
['__aenter__', '__aexit__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api_key', '_build', '_config', '_debug', '_exec', '_load_config', '_session', 'from_session', 'get_acc_balance_by_token_contract_address', 'get_bep20_token_transfer_events_by_address', 'get_bep20_token_transfer_events_by_address_and_contract_paginated', 'get_bep20_token_transfer_events_by_contract_address_paginated', 'get_bep721_token_transfer_events_by_address', 'get_bep721_token_transfer_events_by_address_and_contract_paginated', 'get_bep721_token_transfer_events_by_contract_address_paginated', 'get_block_number_by_timestamp', 'get_block_reward_by_block_number', 'get_bnb_balance', 'get_bnb_balance_multiple', 'get_bnb_last_price', 'get_circulating_supply_by_contract_address', 'get_contract_abi', 'get_contract_source_code', 'get_est_block_countdown_time_by_block_number', 'get_internal_txs_by_address', 'get_internal_txs_by_address_paginated', 'get_internal_txs_by_block_range_paginated', 'get_internal_txs_by_txhash', 'get_logs', 'get_normal_txs_by_address', 'get_normal_txs_by_address_paginated', 'get_proxy_block_by_number', 'get_proxy_block_number', 'get_proxy_block_transaction_count_by_number', 'get_proxy_call', 'get_proxy_code_at', 'get_proxy_est_gas', 'get_proxy_gas_price', 'get_proxy_storage_position_at', 'get_proxy_transaction_by_block_number_and_index', 'get_proxy_transaction_by_hash', 'get_proxy_transaction_count', 'get_proxy_transaction_receipt', 'get_total_bnb_supply', 'get_total_supply_by_contract_address', 'get_tx_receipt_status', 'get_validated_blocks_by_address', 'get_validated_blocks_by_address_paginated', 'get_validators_list']

>>> dir(SyncClient)

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api_key', '_build', '_config', '_debug', '_exec', '_load_config', 'from_session']

get_bep20_token_transfer_events_by_address don't get last blocks [BUG]

When i use this piece of code


if __name__ == "__main__":
    bsc = BscScan("KEY") 
    transactions = bsc.get_bep20_token_transfer_events_by_address(address=WALLET_TO_WATCH",
                                                                  startblock=9512000,
                                                                  endblock=30000935,
                                                                  sort='desc')[:100]
    for transaction in transactions:
        print(int(transaction['blockNumber']) )

I don't receive the last block of the address. The last block number i got is 10511293, but the last block number on the wallet i'm watching is 10512880

Maybe it's blockchain slow to send data with the API ? and i got a delay to get last block ?
I don't understand why there is such a difference between the blocks. By the way, this problem is happening right now, but I don't always have it. For example earlier today I have the last block correctly.

System info (please complete the following information):

  • OS and version: ubuntu 18
  • Python version: 3.8
  • bscscan-python: 1.0.0

[FEATURE] Any way to add token holders information? Thank you

Have you checked the documentation of this package?
โ˜‘๏ธ [Yes/No]

Is the feature on BscScan.com but missing from this package?
โ˜‘๏ธ [Yes/No]
---> If yes, please add a link to the missing feature.

Is your feature request related to a problem? Please describe.
โ˜‘๏ธ A clear and concise description of what the problem is, if any.

Describe the solution you'd like
โ˜‘๏ธ A clear and concise description of what you want to happen.

Describe alternatives you've considered
โ˜‘๏ธ A clear and concise description of any alternative solutions or features you've considered.

Additional context
โ˜‘๏ธ Add any other context or screenshots about the feature request here.

Brython Integration [BUG]

Describe the bug
Installed Bscscan-python and put it into a web using Brython, but the error shows like in the link

To Reproduce
In order to assist you with your problem, we need a minimal code snippet that replicates the bug. Avoid disclosing your API keys.

Steps to reproduce the behavior:

  1. Install Python 3
  2. Embed Brython Script
  3. Test run for balance in <script type="text/python">
  4. Error shows. Link: https://app.mulai.com/landing/iis/contact.html

Tried the run_tests.sh

  1. created a document in root call run_tests.sh
  2. run the suggestion command
  3. error shows as "Coverage: command not found"

Expected behavior
I am expecting to alert balance of an address

Screenshots
If applicable, add screenshots to help explain your problem.
https://www.dropbox.com/sh/8m3dmgnu656m5kt/AABfXhq1Y0tlTeyeW4_kFZnva?dl=0

System info (please complete the following information):

  • OS and version: [e.g. Ubuntu 20.04 LTS]
  • Python version: [e.g. 3.8.5]
  • bscscan-python version: [e.g. 2.0.0]

Additional context
Add any other context about the problem here.

List contracts by symbol

Is there a way to list all contracts by symbol on Bscscan or Bscscan API (currently the search bar doesn't show all contracts when you search by symbol -- max results seems to be set at 15) ?

module methods such as `get_normal_txs_by_address` not working

As mention in #48 some methods of module not wokring as expected, for example get_normal_txs_by_address does return the following trace:

  File "/home/lkonga/Codes/jax-bscscan/main.py", line 36, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/lkonga/Codes/jax-bscscan/main.py", line 15, in main
    await (bsc.get_normal_txs_by_address(address=WALLET_TO_WATCH, startblock=1, endblock=999999, sort="asc"))
  File "/home/lkonga/Codes/jax-bscscan/venv/lib/python3.9/site-packages/bscscan/core/async_client.py", line 27, in wrapper
    return parser.parse(await response.json())
  File "/home/lkonga/Codes/jax-bscscan/venv/lib/python3.9/site-packages/bscscan/utils/parsing.py", line 11, in parse
    assert status, f"{result} -- {message}"
AssertionError: [] -- No transactions found

Process finished with exit code 1

Whilst when accessing API directly, it gives the json data as expected

How to How can I get the balance of a generated token?

Hello,
I am trying to obtain for example the balance of Cake generated in Pancakeswap, I am using the function:

get_acc_balance_by_token_contract_address(contract_address="0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82", address="MYADDRESS")

Where "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82", is the address of pancake, but the result is 0.

Could you guide me to find my mistake?

Thank you

[BUG]

Describe the bug
I tried using the code provided in the readme but I got several errors

To Reproduce
In order to assist you with your problem, we need a minimal code snippet that replicates the bug. Avoid disclosing your API keys.

Steps to reproduce the behavior:

  1. using this code provided in the readme and my api key

import asyncio
from bscscan import BscScan

YOUR_API_KEY = "MY_API_KEY_HERE"

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())

Expected behavior
supposed to return this value:

'167195709084498025431541166'

but returned this instead:

154418307945930954164147431
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x0000025CA8B734C0>
Traceback (most recent call last):
File "E:\Program_Files\Python\Python39\lib\asyncio\proactor_events.py", line 116, in del
self.close()
File "E:\Program_Files\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "E:\Program_Files\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
self._check_closed()
File "E:\Program_Files\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Screenshots
image

System info (please complete the following information):

  • OS and version: Windows 10
  • Python version: 3.9.5
  • bscscan-python version: 2.0.0

Additional context
Add any other context about the problem here.

aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host api.bscscan.com:443 ssl

Describe the bug
When I run the sample, it got error on SSL failed:
SSL handshake failed on verifying the certificate
protocol: <asyncio.sslproto.SSLProtocol object at 0x10e1c2cc0>
transport: <_SelectorSocketTransport fd=9 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 625, in _on_handshake_complete
raise handshake_exc
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 763, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x10e1c2cc0>
transport: <_SelectorSocketTransport closing fd=9 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 763, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
Traceback (most recent call last):
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 970, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 998, in _create_connection_transport
await waiter
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 763, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/treeson/PycharmProjects/bsc_monitor/tests/bsc_api.py", line 15, in
asyncio.run(main())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
return future.result()
File "/Users/treeson/PycharmProjects/bsc_monitor/tests/bsc_api.py", line 12, in main
print(await bsc.get_bnb_balance(address="0x0400034109F339171eAEECC3Fa8948C0C0563E32"))
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/bscscan/core/async_client.py", line 26, in wrapper
async with self._session.get(url) as response:
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/client.py", line 1138, in aenter
self._resp = await self._coro
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/client.py", line 536, in _request
req, traces=traces, timeout=real_timeout
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/connector.py", line 542, in connect
proto = await self._create_connection(req, traces, timeout)
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/connector.py", line 907, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
raise last_exc
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/connector.py", line 1187, in _create_direct_connection
client_error=client_error,
File "/Users/treeson/bsc_monitor/lib/python3.7/site-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host api.bscscan.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)')]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.