software-mansion/starknet.py

error in FullNodeClient, is it RPC error or contract error?

Harsh-fi opened this issue · 0 comments

What happened

    def execute_starknet_transaction(wallet_address:str,public_address:str, private_address:str,to_address:str, starknet_rpc:str,quantized_amount:int, data:str):

        client = FullNodeClient(node_url=starknet_rpc)

        # stark_net_RPC = https://starknet-mainnet.infura.io/v3/574f4fbf2f0b4208a0211a6303288a43
        # contract_address="0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"
        # to_address ='0x0571E140F7e81C56575C702D7B8e074B745a050819685715263xxxxxxxx'

        account = Account(
            client=FullNodeClient(node_url=starknet_rpc),
            address=wallet_address,
            key_pair=KeyPair(
                private_key=private_address,
                public_key=public_address,),
            chain=StarknetChainId.MAINNET,
        )
        contract = Contract(address=contract_address, provider=account, abi=Config.STARK_NET_ABI)

        nonce = account.get_nonce_sync()
        # 33

        max_estimated_gas_fee = StarkNetUtils.max_estimate_gas_fee(
                        contract=contract,
                        nonce=nonce,
                        to_address=to_address,
                        client=client,
                        wallet_address=wallet_address,
                        account=account
                    )
...

Stack trace

Traceback (most recent call last):
  File "/home/user/Desktop/TanX/django/tanx-connector-python/example/starknet_deposit.py", line 37, in <module>
    res = client.starknet_deposit(STARKNET_RPC, STARKNET_WALLET_ADDRESS,STARKNET_PUBLIC_ADDRESS, STARKNET_PRIVATE_KEY,ETH_ADDRESS, amount=3.32, currency='usdc')
  File "/home/user/Desktop/TanX/django/tanx-connector-python/src/tanxconnector/client.py", line 815, in starknet_deposit
    transaction_hash = StarkNetHelper.execute_starknet_transaction( wallet_address,public_address, private_address,to_address,rpc_url,quantized_amount, initiate_res)
  File "/home/user/Desktop/TanX/django/tanx-connector-python/src/tanxconnector/starknet.py", line 125, in execute_starknet_transaction
    max_estimated_gas_fee = StarkNetUtils.max_estimate_gas_fee(
  File "/home/user/Desktop/TanX/django/tanx-connector-python/src/tanxconnector/starknet.py", line 53, in max_estimate_gas_fee
    estimated_fee = cls.estimate_gas_fee(
  File "/home/user/Desktop/TanX/django/tanx-connector-python/src/tanxconnector/starknet.py", line 79, in estimate_gas_fee
    estimated_fee = account._estimate_fee_sync(tx=transaction)
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/starknet_py/utils/sync/sync.py", line 15, in impl
    return sync_fun(*args, **kwargs)
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/asgiref/sync.py", line 254, in __call__
    return call_result.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/asgiref/sync.py", line 331, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/starknet_py/net/account/account.py", line 211, in _estimate_fee
    estimated_fee = await self._client.estimate_fee(
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/starknet_py/net/full_node_client.py", line 347, in estimate_fee
    res = await self._client.call(
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/starknet_py/net/http_client.py", line 101, in call
    self.handle_rpc_error(result)
  File "/home/user/.pyenv/versions/tanx-connector/lib/python3.10/site-packages/starknet_py/net/http_client.py", line 108, in handle_rpc_error
    raise ClientError(
starknet_py.net.client_errors.ClientError: Client failed with code 40: Contract error.

Steps to reproduce

  1. redefine the public and private key
  2. run the function

SDK Version

0.18.7

Python version

3.10.12

What operating system are you using?

Linux

Is there an existing issue for this?

  • I have searched the existing issues and verified no issue exits for this problem.