1

hope someone can help me.

i want to read the nonce (transaction count) and balance for a polygon wallet with web3 package 6.10 and phyton 3.11. get_transaction_count isnt working but the other simple functions work, so it could successfully etablish a connection to the rpc node.

from web3 import Web3
from web3.gas_strategies.time_based import slow_gas_price_strategy

# Configure Web3 to connect to the Polygon
rpc_url = "https://polygon-mainnet.infura.io/v3/{Key}"
account = "0x..."

web3 = Web3(Web3.HTTPProvider(rpc_url))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)

...

if __name__ == "__main__":
    latest_block = web3.eth.get_block('latest') #works

    print(f"chainId: {web3.eth.chain_id}") #works

    print(f"The latest block number is:{web3.eth.block_number}") #works

    res = web3.is_connected()
    print(f"connected: {res}") #works

    is_address_valid = web3.is_address(account)
    print(f"valid address {account}: {res}") #works

    nonce = web3.eth.get_transaction_count(web3.to_checksum_address(account)) #fails
    print(f"nonce {account}")

With Phyton 3.10 and Goerli Etherum it workes but on Polygon and 3.11 it says:

  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\eth\eth.py", line 451, in get_transaction_count
    return self._get_transaction_count(account, block_identifier)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\module.py", line 64, in caller
    (method_str, params), response_formatters = method.process_params(
                                                ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\method.py", line 233, in process_params
    _apply_request_formatters(params, self.request_formatters(method)),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\eth_utils\functional.py", line 45, in inner
    return callback(fn(*args, **kwargs))
                    ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\method.py", line 55, in _apply_request_formatters
    formatted_params = pipe(params, request_formatters)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cytoolz\\functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz\\functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "cytoolz\\functoolz.pyx", line 518, in cytoolz.functoolz.Compose.__call__
  File "cytoolz\\functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\_utils\abi.py", line 746, in map_abi_data
    return pipe(data, *pipeline)
           ^^^^^^^^^^^^^^^^^^^^^
  File "cytoolz\\functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz\\functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "cytoolz\\functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\_utils\abi.py", line 760, in abi_data_tree
    return [
           ^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\_utils\abi.py", line 761, in <listcomp>
    abi_sub_tree(data_type, data_value)
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\web3\_utils\abi.py", line 814, in abi_sub_tree
    abi_type = parse(type_str_or_abi_type)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\eth_abi\grammar.py", line 123, in parse
    return super().parse(type_str, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 252, in parse
    return self._parse_or_match(text, pos, 'parse')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 287, in _parse_or_match
    return self.visit(getattr(self.grammar, method_name)(text, pos=pos))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 213, in visit
    return method(node, [self.visit(n) for n in node])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 213, in <listcomp>
    return method(node, [self.visit(n) for n in node])
                         ^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 213, in visit
    return method(node, [self.visit(n) for n in node])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 213, in <listcomp>
    return method(node, [self.visit(n) for n in node])
                         ^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Project\venv_311\Lib\site-packages\parsimonious\nodes.py", line 225, in visit
    raise VisitationError(exc, exc_class, node) from exc
parsimonious.exceptions.VisitationError: TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union
3
  • Can you manually confirm that the underlying JSON-RPC call works by calling it with curl or similar command line tool? Otherwise could be a bug in web3.py. Commented Sep 26, 2023 at 21:35
  • dont know how to call it manually against infura node but with the old phyton version the code works perfect, only with the new phyton version it fails. so shouldnt be an rpc issue Commented Sep 27, 2023 at 16:42
  • i opened a ticket on their github repo, good point if its a bug on their side Commented Sep 27, 2023 at 16:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.