Code Monkey home page Code Monkey logo

zksync2-python's Issues

timeout with withdraw

https://github.com/zksync-sdk/zksync2-python/blob/master/examples/11_withdrawal.py

I try run this example and get errors like this:

Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\zksync2\module\zksync_module.py", line 383, in wait_finalized
_timeout.sleep(poll_latency)
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\web3_utils\threads.py", line 99, in sleep
self.check()
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\web3_utils\threads.py", line 92, in check
raise self
web3._utils.threads.Timeout: 240 seconds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\zksync\main2.py", line 141, in
example_withdrawal(0.0001)
File "C:\Users\User\PycharmProjects\zksync\main2.py", line 70, in example_withdrawal
zks_receipt = web3.zksync.wait_finalized(tx_hash, timeout=240, poll_latency=0.5)
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\zksync2\module\zksync_module.py", line 387, in wait_finalized
raise TimeExhausted(
web3.exceptions.TimeExhausted: Transaction HexBytes('0x8a47e826e7ae59fb9034b05b5af1ef3a0ad160ba1c50930da8d2e7b116fcbfa9') is not in the chain after 240 seconds

Unable to verify compiled and deployed contract

I made the docker image as described here:

https://github.com/zksync-sdk/zksync2-python/blob/master/examples/README.md

zksolc binary I used that:

https://github.com/matter-labs/zksolc-bin/raw/main/linux-amd64/zksolc-linux-amd64-musl-v1.3.9

Compile:

zksolc -O3 -o solidity/hello_world/build --combined-json abi,bin solidity/hello_world/Hello.sol

combined.json:

{"contracts":{"solidity/hello_world/Hello.sol:HelloWorld":{"abi":[{"inputs":[],"name":"sayHelloWorld","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"}],"bin":"000100000000000200000000030100190000006003300270000000150030019d00000015033001970000000102200190000000420000c13d000000040230008c0000004c0000413d000000000101043b0000001701100197000000180110009c0000004c0000c13d0000000001000416000000000110004c0000004c0000c13d000000040100008a00000000011000310000001902000041000000000310004c000000000300001900000000030240190000001901100197000000000410004c000000000200a019000000190110009c00000000010300190000000001026019000000000110004c0000004c0000c13d000000c001000039000000400010043f0000000b01000039000000800010043f0000001a01000041000000a00010043f0000002002000039000000400100043d0000000003210436000000800200043d00000000002304350000004003100039000000000420004c000000340000613d00000000040000190000000005340019000000a006400039000000000606043300000000006504350000002004400039000000000524004b0000002d0000413d000000000332001900000000000304350000005f02200039000000200300008a000000000232016f0000001503000041000000150420009c0000000002038019000000150410009c000000000103801900000040011002100000006002200210000000000112019f0000004f0001042e0000008001000039000000400010043f0000000001000416000000000110004c0000004c0000c13d00000020010000390000010000100443000001200000044300000016010000410000004f0001042e000000000100001900000050000104300000004e000004320000004f0001042e000000500001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0000000200000000000000000000000000000040000001000000000000000000ffffffff0000000000000000000000000000000000000000000000000000000045773e4e00000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000048656c6c6f20576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cb47313f6730af34ce24f06b76216301a9ea6acf671fd7a505cf691ced9070b2","factory-deps":{}}},"version":"0.8.19+commit.7dd6d404.Linux.g++","zk_version":"1.3.9"}

After deploy I try to verify smart contract:

https://goerli.explorer.zksync.io/contracts/verify?address=0xd932ab3e4768daC5A760DFE38a9F726c7Aec158f

Zksolc ver: 1.3.9, Solc 0.8.19, Contract Name: HelloWorld, Contract Path: solidity/hello_world/Hello.sol

And paste Hello.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
contract HelloWorld {
    function sayHelloWorld() public pure returns (string memory) {
        return "Hello World";
    }
}

Then I get an error: Deployed bytecode is not equal to generated one from given source.

KeyError: 'l1EthDefaultBridge'

Hello?

File "main.py", line 31, in
deposit()
File "main.py", line 20, in deposit
eth_provider = EthereumProvider.build_ethereum_provider(zksync=zksync_web3,
File "/usr/local/lib/python3.8/dist-packages/zksync2/provider/eth_provider.py", line 36, in build_ethereum_provider
bridge_contracts: BridgeAddresses = zksync.zksync.zks_get_bridge_contracts()
File "/usr/local/lib/python3.8/dist-packages/zksync2/module/zksync_module.py", line 271, in zks_get_bridge_contracts
return self._zks_get_bridge_contracts()
File "/usr/local/lib/python3.8/dist-packages/web3/module.py", line 61, in caller
return apply_result_formatters(result_formatters, result)
File "cytoolz/functoolz.pyx", line 249, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.8/dist-packages/web3/module.py", line 38, in apply_result_formatters
formatted_result = pipe(result, result_formatters)
File "cytoolz/functoolz.pyx", line 666, in cytoolz.functoolz.pipe
File "cytoolz/functoolz.pyx", line 641, in cytoolz.functoolz.c_pipe
File "cytoolz/functoolz.pyx", line 502, in cytoolz.functoolz.Compose.call
File "/usr/local/lib/python3.8/dist-packages/zksync2/module/zksync_module.py", line 105, in to_bridge_address
return BridgeAddresses(l1_eth_default_bridge=HexStr(to_checksum_address(t["l1EthDefaultBridge"])),
KeyError: 'l1EthDefaultBridge'

When will you fix it?

Failed to run test_deposit in test_zksync_web3.py

When I try to run test case test_deposit in test_zksync_web3.py, it throws

  File "/usr/local/lib/python3.9/site-packages/zksync2/module/zksync_module.py", line 105, in to_bridge_address
    return BridgeAddresses(l1_eth_default_bridge=HexStr(to_checksum_address(t["l1EthDefaultBridge"])),
KeyError: 'l1EthDefaultBridge'

It looks like there is no l1EthDefaultBridge in a dict. Is it a bug or my setting is wrong?

Make target fails with: 17.62 Processing pydantic_core-2.4.0.tar.gz

#0 17.62 Processing pydantic_core-2.4.0.tar.gz
#0 17.73 error: Couldn't find a setup script in /tmp/easy_install-y861t2v5/pydantic_core-2.4.0.tar.gz
------
failed to solve: process "/bin/bash -c python3 setup.py install" did not complete successfully: exit code: 1
make: *** [test] Error 17

txn 113

How do I send transaction type 113 to zksync sdk?
I know that this is a transaction of type eip-712 but I can’t do it
1234

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing package.json file.

A package.json file at the root of your project is required to release on npm.

Please follow the npm guideline to create a valid package.json file.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Unable to install zksync2-python SDK on Python 3.10 on Mac

I'm trying to install the zksync2-python SDK on my Mac running Python 3.10, but I'm running into issues. Here's the error message I'm seeing:

pip install zksync2


Building wheels for collected packages: pysha3
  Building wheel for pysha3 (setup.py) ... error
  error: subprocess-exited-with-error
  
  Γ— python setup.py bdist_wheel did not run successfully.
  β”‚ exit code: 1
  ╰─> [14 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-310
      copying sha3.py -> build/lib.macosx-10.9-x86_64-cpython-310
      running build_ext
      building '_pysha3' extension
      creating build/temp.macosx-10.9-x86_64-cpython-310
      creating build/temp.macosx-10.9-x86_64-cpython-310/Modules
      creating build/temp.macosx-10.9-x86_64-cpython-310/Modules/_sha3
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/joe/.conda/envs/pythonProject-web3/include -fPIC -O2 -isystem /Users/joe/.conda/envs/pythonProject-web3/include -DPY_WITH_KECCAK=1 -I/Users/joe/.conda/envs/pythonProject-web3/include/python3.10 -c Modules/_sha3/sha3module.c -o build/temp.macosx-10.9-x86_64-cpython-310/Modules/_sha3/sha3module.o
      xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pysha3
  Running setup.py clean for pysha3
Failed to build pysha3
Installing collected packages: pysha3, eip712-structs, web3, zksync2
  Running setup.py install for pysha3 ... error
  error: subprocess-exited-with-error
  
  Γ— Running setup.py install for pysha3 did not run successfully.
  β”‚ exit code: 1
  ╰─> [27 lines of output]
      running install
      /Users/joe/.conda/envs/pythonProject-web3/lib/python3.10/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
      !!
      
              ****************************************************************************
              Please avoid running `setup.py` directly.
              Instead, use pypa/build, pypa/installer, pypa/build or
              other standards-based tools.
      
              See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
              ****************************************************************************
      
      !!
        self.initialize_options()
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-310
      copying sha3.py -> build/lib.macosx-10.9-x86_64-cpython-310
      running build_ext
      building '_pysha3' extension
      creating build/temp.macosx-10.9-x86_64-cpython-310
      creating build/temp.macosx-10.9-x86_64-cpython-310/Modules
      creating build/temp.macosx-10.9-x86_64-cpython-310/Modules/_sha3
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/joe/.conda/envs/pythonProject-web3/include -fPIC -O2 -isystem /Users/joe/.conda/envs/pythonProject-web3/include -DPY_WITH_KECCAK=1 -I/Users/joe/.conda/envs/pythonProject-web3/include/python3.10 -c Modules/_sha3/sha3module.c -o build/temp.macosx-10.9-x86_64-cpython-310/Modules/_sha3/sha3module.o
      xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

Γ— Encountered error while trying to install package.
╰─> pysha3

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

I've tried a few different things to troubleshoot the issue, including downgrading my Python version to 3.8, Create a new conda environment, but the error still persists.

Any ideas on what might be causing this issue and how I can resolve it? Any help would be greatly appreciated!

Thanks,
yy

eth_estimate_gas always return web3.exceptions.ContractLogicError: execution reverted: Failed to submit transaction: cannot estimate gas

       account: LocalAccount = Account.from_key(self.private_key)

        # Get chain id of zkSync network
        chain_id = self.web3.zksync.chain_id

        # Signer is used to generate signature of provided transaction
        signer = PrivateKeyEthSigner(account, chain_id)

        # Get nonce of ETH address on zkSync network
        nonce = self.web3.zksync.get_transaction_count(
            account.address, ZkBlockParams.COMMITTED.value
        )

        # Get current gas price in Wei
        gas_price = self.web3.zksync.gas_price

        # Create transaction
        tx_func_call = TxFunctionCall(
            chain_id=chain_id,
            nonce=nonce,
            from_=account.address,
            to=to_checksum_address(to_address),
            value=self.web3.to_wei(amount, "ether"),
            data=HexStr("0x8722b9f70000000000000000000000000000000000000000000000000000000000000001"),
            gas_limit=10000000,  # UNKNOWN AT THIS STATE
            gas_price=gas_price,
            max_priority_fee_per_gas=100000000,
        )

        # ZkSync transaction gas estimation
        estimate_gas = self.web3.zksync.eth_estimate_gas(tx_func_call.tx)
        print(f"Fee for transaction is: {estimate_gas * gas_price}")

        # Convert transaction to EIP-712 format
        tx_712 = tx_func_call.tx712(estimate_gas)

        # Sign message & encode it
        signed_message = signer.sign_typed_data(tx_712.to_eip712_struct())

        # Encode signed message
        msg = tx_712.encode(signed_message)

        # Transfer ETH
        tx_hash = self.web3.zksync.send_raw_transaction(msg)
        print(f"Transaction hash is : {tx_hash.hex()}")

the error message is weird, i have enough eth in my wallet for gas use

INTERNAL_ERROR: insufficient funds

Maybe someone can help me troubleshoot why?
account balance should be fine: 0.00311887674881946
try sending 0.001

def deposit(private_key, amount):
    try:
        account: LocalAccount = Account.from_key(private_key)
        zk_web3 = ZkSyncBuilder.build("https://testnet.era.zksync.dev")
        eth_web3 = Web3(Web3.HTTPProvider("https://rpc.ankr.com/eth_goerli")
        print(eth_web3.eth.block_number)
        eth_provider = EthereumProvider(zk_web3, eth_web3, account)
        print("Executing deposit transaction on L1 network")
        l1_tx_receipt = eth_provider.deposit(
            token=Token.create_eth(),
            amount=eth_web3.to_wei(amount, "ether"),
            gas_price=eth_web3.eth.gas_price
        )
        # Check if deposit transaction was successful
        if not l1_tx_receipt["status"]:
            raise RuntimeError("Layer 1 error")

        return l1_tx_receipt["transactionHash"].hex()

    except Exception as e:
        print(f"deposit error: {e}")
        return
    return

And logging debug

2023-06-11 10:08:35,072 - DEBUG - Making request. Method: zks_getMainContract
2023-06-11 10:08:35,073 - DEBUG - make_request: zks_getMainContract, params : ()
2023-06-11 10:08:35,073 - DEBUG - Making request HTTP. URI: https://testnet.era.zksync.dev, Method: zks_getMainContract
2023-06-11 10:08:35,074 - DEBUG - Session cached: https://testnet.era.zksync.dev, <requests.sessions.Session object at 0x000001C3D6592B80>
2023-06-11 10:08:35,075 - DEBUG - Starting new HTTPS connection (1): testnet.era.zksync.dev:443
2023-06-11 10:08:36,013 - DEBUG - https://testnet.era.zksync.dev:443 "POST / HTTP/1.1" 200 None
2023-06-11 10:08:36,013 - DEBUG - Getting response HTTP. URI: https://testnet.era.zksync.dev, Method: zks_getMainContract, Response: {'jsonrpc': '2.0', 'result': '0x1908e2bf4a88f91e4ef0dc72f02b8ea36bea2319', 'id': 0}
2023-06-11 10:08:36,024 - DEBUG - Making request. Method: eth_chainId
2023-06-11 10:08:36,025 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId
2023-06-11 10:08:36,358 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 39
2023-06-11 10:08:36,359 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId, Response: {'jsonrpc': '2.0', 'id': 1, 'result': '0x5'}
2023-06-11 10:08:36,360 - DEBUG - Making request. Method: zks_getBridgeContracts
2023-06-11 10:08:36,360 - DEBUG - make_request: zks_getBridgeContracts, params : ()
2023-06-11 10:08:36,361 - DEBUG - Making request HTTP. URI: https://testnet.era.zksync.dev, Method: zks_getBridgeContracts
2023-06-11 10:08:36,638 - DEBUG - https://testnet.era.zksync.dev:443 "POST / HTTP/1.1" 200 None
2023-06-11 10:08:36,638 - DEBUG - Getting response HTTP. URI: https://testnet.era.zksync.dev, Method: zks_getBridgeContracts, Response: {'jsonrpc': '2.0', 'result': {'l1Erc20DefaultBridge': '0x927ddfcc55164a59e0f33918d13a2d559bc10ce7', 'l2Erc20DefaultBridge': '0x00ff932a6d70e2b8f1eb4919e1e09c1923e7e57b'}, 'id': 1}
Executing deposit transaction on L1 network
2023-06-11 10:08:36,644 - DEBUG - Making request. Method: eth_gasPrice
2023-06-11 10:08:36,644 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_gasPrice
2023-06-11 10:08:36,936 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 42
2023-06-11 10:08:36,937 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_gasPrice, Response: {'jsonrpc': '2.0', 'id': 2, 'result': '0x119b'}
2023-06-11 10:08:36,938 - DEBUG - Making request. Method: eth_getTransactionCount
2023-06-11 10:08:36,938 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_getTransactionCount
2023-06-11 10:08:37,289 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 39
2023-06-11 10:08:37,290 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_getTransactionCount, Response: {'jsonrpc': '2.0', 'id': 3, 'result': '0x1'}
2023-06-11 10:08:37,291 - DEBUG - Making request. Method: eth_call
2023-06-11 10:08:37,292 - DEBUG - Making request. Method: eth_chainId
2023-06-11 10:08:37,292 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId
2023-06-11 10:08:37,537 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 39
2023-06-11 10:08:37,537 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId, Response: {'jsonrpc': '2.0', 'id': 4, 'result': '0x5'}
2023-06-11 10:08:37,538 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_call
2023-06-11 10:08:37,834 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 None
2023-06-11 10:08:37,834 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_call, Response: {'jsonrpc': '2.0', 'id': 5, 'result': '0x0000000000000000000000000000000000000000000000000011c37937e08000'}
2023-06-11 10:08:37,835 - DEBUG - Making request. Method: eth_getTransactionCount
2023-06-11 10:08:37,836 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_getTransactionCount
2023-06-11 10:08:38,104 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 39
2023-06-11 10:08:38,104 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_getTransactionCount, Response: {'jsonrpc': '2.0', 'id': 6, 'result': '0x1'}
2023-06-11 10:08:38,106 - DEBUG - Making request. Method: eth_call
2023-06-11 10:08:38,106 - DEBUG - Making request. Method: eth_chainId
2023-06-11 10:08:38,106 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId
2023-06-11 10:08:38,394 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 39
2023-06-11 10:08:38,395 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId, Response: {'jsonrpc': '2.0', 'id': 7, 'result': '0x5'}
2023-06-11 10:08:38,397 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_call
2023-06-11 10:08:38,683 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 None
2023-06-11 10:08:38,683 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_call, Response: {'jsonrpc': '2.0', 'id': 8, 'result': '0x0000000000000000000000000000000000000000000000000011c37937e08000'}
2023-06-11 10:08:38,684 - DEBUG - Making request. Method: eth_getTransactionCount
2023-06-11 10:08:38,686 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_getTransactionCount
2023-06-11 10:08:38,975 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 39
2023-06-11 10:08:38,976 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_getTransactionCount, Response: {'jsonrpc': '2.0', 'id': 9, 'result': '0x1'}
2023-06-11 10:08:38,978 - DEBUG - Making request. Method: eth_chainId
2023-06-11 10:08:38,978 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId
2023-06-11 10:08:39,313 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 40
2023-06-11 10:08:39,314 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_chainId, Response: {'jsonrpc': '2.0', 'id': 10, 'result': '0x5'}
2023-06-11 10:08:39,322 - DEBUG - Making request. Method: eth_sendRawTransaction
2023-06-11 10:08:39,322 - DEBUG - Making request HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_sendRawTransaction
2023-06-11 10:08:39,816 - DEBUG - https://rpc.ankr.com:443 "POST /eth_goerli HTTP/1.1" 200 None
2023-06-11 10:08:39,817 - DEBUG - Getting response HTTP. URI: https://rpc.ankr.com/eth_goerli, Method: eth_sendRawTransaction, Response: {'jsonrpc': '2.0', 'id': 11, 'error': {'code': -32000, 'message': 'INTERNAL_ERROR: insufficient funds'}}

eth_estimate_gas: web3.exceptions.ContractLogicError: execution reverted: Failed to submit transaction: insufficient balance for transfer

There is no problem with the testnet, but there will be errors when using it on the mainnet

rom eth_account import Account
from eth_account.signers.local import LocalAccount
from web3 import Web3
from zksync2.module.request_types import EIP712Meta

from zksync2.core.types import Token, EthBlockParams
from zksync2.module.module_builder import ZkSyncBuilder
from zksync2.provider.eth_provider import EthereumProvider


ZKSYNC_MAIN_URL = "https://mainnet.era.zksync.io"
ETH_TEST_URL = "hhttps://rpc.flashbots.net"
PRIVATE_KEY = "MYPRIVATEKEY"

def deposit(amount: float):

    zksync = ZkSyncBuilder.build(ZKSYNC_TEST_URL)
    eth_web3 = Web3(Web3.HTTPProvider(ETH_TEST_URL))
    account: LocalAccount = Account.from_key(PRIVATE_KEY)
    eth_provider = EthereumProvider(zksync, eth_web3, account)
    chain_id = zksync.zksync.chain_id
    wei_amount = Web3.to_wei(amount, "ether")
    eth_token = Token.create_eth()
    
   addres = Web3.to_checksum_address("my_address")
    l2_gas_limit = eth_provider._zksync_web3.zksync.eth_estimate_gas({
        'value': self.web3.to_hex(wei_amount),
        'from': address,
        'to': to_address,
        'data': '0x',
        'eip712Meta': EIP712Meta(gas_per_pub_data=0)
    })



if __name__ == "__main__":
    deposit(0.1)

network zksync era main

error msg:

Exception has occurred: ContractLogicError
execution reverted: Failed to submit transaction: insufficient balance for transfer
  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\zksync_era.py", line 64, in zksync_era_deposit_for_eth
    l2_gas_limit = self.web3_other._zksync_web3.zksync.eth_estimate_gas({
web3.exceptions.ContractLogicError: execution reverted: Failed to submit transaction: insufficient balance for transfer

During handling of the above exception, another exception occurred:

  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\zksync_era.py", line 74, in zksync_era_deposit_for_eth
    raise web3_exceptions.ContractLogicError(e)
  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\web3_utils.py", line 125, in _inner
    return func(self, **params)
  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\web3_utils.py", line 91, in _inner
    return func(self, *args, address=address, private_key=private_key, **kwargs)
  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\web3_utils.py", line 66, in _inner
    result = func(self, *args, **kwargs)
  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\zksync_era.py", line 110, in zksync_era_deposit_for_main
    action_result = self.zksync_era_deposit_for_eth(amount=amount, to_address=receiver,
  File "D:\CodeProject\blockchain\blockchain_new\source_interaction\base\zksync_era.py", line 121, in <module>
    ze.zksync_era_deposit_for_main(amount=0.02, from_=2, to_=2)
web3.exceptions.ContractLogicError: execution reverted: Failed to submit transaction: insufficient balance for transfer

image

Is this the estimated gas on the zksync era, or am I getting it wrong?

I want to know which function is called by the following interface
image

[bug] L1->L2 deposit fails due to t["l1WethBridge"] being None

With the introduction of new chain deployments that feature shared bridges, I believe the concepts of 'l1WethBridge' and 'l2WethBridge' are now obsolete.
When attempting to make a deposit from L1 to L2, I encounter an error because None is being passed to to_checksum_address, resulting in issues with these lines

Issues when interacting with a local node

Hi

I am trying to set up a test environment for the example python modules that are available in this repository.
Whenever I fork the zksync testnet to my local enivronment through anvil and try to run one of the example modules I always get all kind of errors but if I try to run one of the modules with a remote testnet provider everything is fine.
Is this SDK compatible with only remote testnet node ?

For example by running this snippet code with a local provider :

PROVIDER  =  "http://127.0.0.1:8545"
zk = ZkSyncBuilder.build(PROVIDER)
PRIVATE_KEY = bytes.fromhex(key)
ACCOUNT: LocalAccount = Account.from_key(PRIVATE_KEY)
nonce = w3.zksync.get_transaction_count(ACCOUNT.address, ZkBlockParams.COMMITTED.value)
print(nonce)

I get this error :

Traceback (most recent call last):
  File "/home/andy/Desktop/medium/zk/zk/try.py", line 54, in <module>
    nonce = w3.zksync.get_transaction_count(ACCOUNT.address, ZkBlockParams.COMMITTED.value)
  File "/home/andy/Desktop/medium/zk/.venv/lib/python3.10/site-packages/web3/eth/eth.py", line 450, in get_transaction_count
    return self._get_transaction_count(account, block_identifier)
  File "/home/andy/Desktop/medium/zk/.venv/lib/python3.10/site-packages/web3/module.py", line 68, in caller
    result = w3.manager.request_blocking(
  File "/home/andy/Desktop/medium/zk/.venv/lib/python3.10/site-packages/web3/manager.py", line 232, in request_blocking
    return self.formatted_response(
  File "/home/andy/Desktop/medium/zk/.venv/lib/python3.10/site-packages/web3/manager.py", line 205, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32602, 'message': 'invalid digit found in string'}

But if I replace a local provider with a remote provider like "https://zksync2-testnet.zksync.dev" I don't get any errors.

Any suggestions ? I fork the zksync testnet through anvil --fork-url https://zksync2-testnet.zksync.dev

Example deposit testnet transaction fails on chain: "Fail with error 'qp'"

Hi everyone

I am trying out the Deposit example (https://github.com/zksync-sdk/zksync2-python/blob/master/examples/01_deposit.py). However, the processed transaction fails on chain with the error "Fail with error 'qp'" (example transaction: https://goerli.etherscan.io/tx/0xfd2e00f9bec156ba7bf5fdfcbfd4a4e178a3907993a723e8b871db7406111183).

Reproducable code

from eth_account import Account
from eth_account.signers.local import LocalAccount
from web3 import Web3

from zksync2.core.types import Token, EthBlockParams
from zksync2.module.module_builder import ZkSyncBuilder
from zksync2.provider.eth_provider import EthereumProvider

PRIVATE_KEY = open("./private-keys/testnet-test-account.key", "r").read()
ZKSYNC_TEST_URL = "https://zksync2-testnet.zksync.dev"
RCP_ENDPOINT = "https://rpc.ankr.com/eth_goerli/<REDACTED API KEY>"

def deposit(amount: float):
    zksync = ZkSyncBuilder.build(ZKSYNC_TEST_URL)
    eth_web3 = Web3(Web3.HTTPProvider(RCP_ENDPOINT))
    account: LocalAccount = Account.from_key(PRIVATE_KEY)
    eth_provider = EthereumProvider(zksync, eth_web3, account)
    wei_amount = Web3.to_wei(amount, "ether")
    eth_token = Token.create_eth()
    gas_price = eth_web3.eth.gas_price
    before_deposit = eth_provider.get_l1_balance(eth_token, EthBlockParams.LATEST)

    print(f"Before: {before_deposit}")

    l1_tx_receipt = eth_provider.deposit(token=Token.create_eth(),
                                         amount=wei_amount,
                                         gas_price=gas_price)
    print(l1_tx_receipt)


if __name__ == "__main__":
    deposit(0.01)

Any ideas? Could it be the suggested gas constants in the SDK?

insufficient funds

why I get error insufficient funds? I have enough funds and make a small deposit.
network goerli

C:\Users\User\PycharmProjects\zksync\venv\Scripts\python.exe C:/Users/User/PycharmProjects/zksync/main2.py
Before: 92462052031320569
0.092462052031320569
current_gas_price= 174.638303826
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\zksync\main2.py", line 140, in
deposit(0.0000000000002)
File "C:\Users\User\PycharmProjects\zksync\main2.py", line 116, in deposit
l1_tx_receipt = eth_provider.deposit(token=Token.create_eth(),
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\zksync2\provider\eth_provider.py", line 132, in deposit
return self.request_execute(
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\zksync2\provider\eth_provider.py", line 187, in request_execute
tx_receipt = self.main_contract.request_l2_transaction(contract_l2=contract_address,
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\zksync2\manage_contracts\zksync_contract.py", line 420, in request_l2_transaction
tx_hash = self.web3.eth.send_raw_transaction(signed_tx.rawTransaction)
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\web3\eth\eth.py", line 372, in send_raw_transaction
return self._send_raw_transaction(transaction)
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\web3\module.py", line 68, in caller
result = w3.manager.request_blocking(
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\web3\manager.py", line 232, in request_blocking
return self.formatted_response(
File "C:\Users\User\PycharmProjects\zksync\venv\lib\site-packages\web3\manager.py", line 205, in formatted_response
raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'INTERNAL_ERROR: insufficient funds'}

Process finished with exit code 1

pip install zksync2 fail

It not works for pip install zksync2. Get the error:

Building wheels for collected packages: pysha3
Building wheel for pysha3 (setup.py) ... error
error: subprocess-exited-with-error
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pysha3

eth_estimate_gas error in testnet

image

I'm using zkSync Era testnet for test transfer eth use python code, but it had ContractLogicError(execution reverted) when use zksync.eth_estimate_gas method, I'm sure the wallet has enough eth(0.00988 eth) only transfer 0.0001 eth to other wallet,
my python envoriment: python 3.10 & zksync2 0.6.0
the code is forked from examples/02_transfer.py

could someone help me to fix it?

Missing field gasPerPubdata

When trying to run example transfers from the readme, getting the following error:

Traceback (most recent call last):
  File "/Users/user/run.py", line 31, in <module>
    zksync.transfer(zksync_web3, account, 0.0000001, item)
  File "/Users/user/run.py", line 46, in transfer
    estimate_gas = zksync_web3.zksync.eth_estimate_gas(tx_func_call.tx)
  File "/Users/user/.pyenv/versions/3.10.2/lib/python3.10/site-packages/zksync2/module/zksync_module.py", line 284, in eth_estimate_gas
    return self._eth_estimate_gas(tx)
  File "/Users/user/.pyenv/versions/3.10.2/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/Users/user/.pyenv/versions/3.10.2/lib/python3.10/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/Users/user/.pyenv/versions/3.10.2/lib/python3.10/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32602, 'message': 'Invalid params: missing field `gasPerPubdata`.'}

pysha3 conflict

When I installing, I always get this error:ERROR: Could not build wheels for pysha3, which is required to install pyproject.toml-based projects

I tried install pysha3 manually, but also get this error. Also I have created a empty pyproject.toml - nothing

Missing l1EthDefaultBridge

when I run the example deposit, I got the error as follow:
Traceback (most recent call last):
File "/Users/jackliu/workspace/zkSync/dev-sync/deposit.py", line 44, in
deposit()
File "/Users/jackliu/workspace/zkSync/dev-sync/deposit.py", line 24, in deposit
eth_provider = EthereumProvider.build_ethereum_provider(
File "/Users/jackliu/workspace/zkSync/dev-sync/venv/lib/python3.9/site-packages/zksync2/provider/eth_provider.py", line 36, in build_ethereum_provider
bridge_contracts: BridgeAddresses = zksync.zksync.zks_get_bridge_contracts()
File "/Users/jackliu/workspace/zkSync/dev-sync/venv/lib/python3.9/site-packages/zksync2/module/zksync_module.py", line 271, in zks_get_bridge_contracts
return self._zks_get_bridge_contracts()
File "/Users/jackliu/workspace/zkSync/dev-sync/venv/lib/python3.9/site-packages/web3/module.py", line 61, in caller
return apply_result_formatters(result_formatters, result)
File "cytoolz/functoolz.pyx", line 249, in cytoolz.functoolz.curry.call
File "/Users/jackliu/workspace/zkSync/dev-sync/venv/lib/python3.9/site-packages/web3/module.py", line 38, in apply_result_formatters
formatted_result = pipe(result, result_formatters)
File "cytoolz/functoolz.pyx", line 666, in cytoolz.functoolz.pipe
File "cytoolz/functoolz.pyx", line 641, in cytoolz.functoolz.c_pipe
File "cytoolz/functoolz.pyx", line 502, in cytoolz.functoolz.Compose.call
File "/Users/jackliu/workspace/zkSync/dev-sync/venv/lib/python3.9/site-packages/zksync2/module/zksync_module.py", line 105, in to_bridge_address
return BridgeAddresses(l1_eth_default_bridge=HexStr(to_checksum_address(t["l1EthDefaultBridge"])),
KeyError: 'l1EthDefaultBridge'

Building wheel for bitarray (pyproject.toml) did not run successfully

pip install zksync2

There is a problem after using the command, which cannot be solved
Whether I install Visual Studio or download the local installation bitarray-2.5.1-cp38-cp38-win_amd64. whl in advance, it is the same error
My python version is 3.8. How to solve this problem

β€”β€”β€”β€”β€”β€”β€”β€”
1

Building wheels for collected packages: bitarray, pysha3
Building wheel for bitarray (pyproject.toml) ... error
error: subprocess-exited-with-error

Γ— Building wheel for bitarray (pyproject.toml) did not run successfully.
β”‚ exit code: 1
╰─> [1 lines of output]
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for bitarray
Building wheel for pysha3 (pyproject.toml) ... error
error: subprocess-exited-with-error

Γ— Building wheel for pysha3 (pyproject.toml) did not run successfully.
β”‚ exit code: 1
╰─> [9 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-38
copying sha3.py -> build\lib.win-amd64-cpython-38
running build_ext
building '_pysha3' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pysha3
Failed to build bitarray pysha3
ERROR: Could not build wheels for bitarray, pysha3, which is required to install pyproject.toml-based projects

The block explorer always says "Fail with error 'mv'" error

use python
0x8a0f0ef395d4633369d74a374fc81e60ead6a06af30a51e3c6b02593e1555946
UZ@{QDE`HQ$U_QA1O6WN K

from web3 import Web3
from eth_account import Account
from web3.middleware import geth_poa_middleware
from eth_account.signers.local import LocalAccount
from source_interaction.zksync2_python_develop.zksync2.module.module_builder import ZkSyncBuilder
from source_interaction.zksync2_python_develop.zksync2.core.types import Token
from source_interaction.zksync2_python_develop.zksync2.provider.eth_provider import EthereumProvider
from source_interaction.zksync2_python_develop.zksync2.core.types import Token, EthBlockParams


URL_TO_ETH_NETWORK = "https://endpoints.omniatech.io/v1/eth/goerli/public"
URL_TO_ETH_NETWORK = "https://goerli.infura.io/v3/"
ZKSYNC_NETWORK_URL = "https://zksync2-testnet.zksync.dev"

PRIVATE_KEY2 = bytes.fromhex("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")


def deposit(amount: float):
    zksync = ZkSyncBuilder.build(ZKSYNC_NETWORK_URL)
    eth_web3 = Web3(Web3.HTTPProvider(URL_TO_ETH_NETWORK))
    eth_web3.middleware_onion.inject(geth_poa_middleware, layer=0)
    account: LocalAccount = Account.from_key(PRIVATE_KEY2)
    eth_provider = EthereumProvider(zksync, eth_web3, account)
    wei_amount = Web3.to_wei(amount, "ether")
    eth_token = Token.create_eth()
    gas_price = int(eth_web3.eth.gas_price * 1.1)
    before_deposit = eth_provider.get_l1_balance(eth_token, EthBlockParams.LATEST)
    eth_provider._zksync_web3.zksync
    print(f"Before: {before_deposit}")
    addres = Web3.to_checksum_address("0x79a5b5916665735fdde66eeacb4e62628416d56c")
    l2_gas_limit = eth_provider._zksync_web3.zksync.eth_estimate_gas({
        "value":"0x38d7ea4c68000", 
        "from": addres,
        "to": addres,
        "data":"0x",
        # "eip712Meta":{"gasPerPubdata":"0x0"}
    }) # int(733664 * 2) # int(eth_provider._zksync_web3.eth.gas_price * 1.1)
    gas_per_pubdata_byte = None # 800
    gas_limit = None # 118722

    l1_tx_receipt = eth_provider.deposit(token=eth_token,
                                         amount=wei_amount,
                                         l2_gas_limit=l2_gas_limit,
                                         gas_limit=gas_limit,
                                         gas_per_pubdata_byte=gas_per_pubdata_byte,
                                         gas_price=gas_price)
    # TODO: when L2 tx

    after = eth_provider.get_l1_balance(eth_token, EthBlockParams.LATEST)
    print(f"After : {after}")

    print(f"Tx status: {l1_tx_receipt['status']}")


if __name__ == '__main__':
    deposit(0.001)

`

use javascript
0x51ee30a9b0936c76051acf07fc0b10099a002bd22105e9f279d2f60c66c55fcf
21H%N}{2J4B~GRWFWX_FTO7

The hashes they generate don't look any different, but using the python module always produces an error

deposit.py module errors

Hi . I am trying to run your deposit.py example but it seems the module throws me 2 errors.

from eth_account import Account
from eth_account.signers.local import LocalAccount
from web3 import Web3

from zksync2.core.types import Token, EthBlockParams
from zksync2.module.module_builder import ZkSyncBuilder
from zksync2.provider.eth_provider import EthereumProvider


ZKSYNC_TEST_URL = "https://zksync2-testnet.zksync.dev"
ETH_TEST_URL = "https://rpc.ankr.com/eth_sepolia"
PRIVATE_KEY = "MYPRIVATEKEY"

def deposit(amount: float):

    zksync = ZkSyncBuilder.build(ZKSYNC_TEST_URL)
    eth_web3 = Web3(Web3.HTTPProvider(ETH_TEST_URL))
    account: LocalAccount = Account.from_key(PRIVATE_KEY)
    eth_provider = EthereumProvider(zksync, eth_web3, account)
    chain_id = zksync.zksync.chain_id
    wei_amount = Web3.to_wei(amount, "ether")
    eth_token = Token.create_eth()
    print(eth_token)
    gas_price = eth_web3.eth.gas_price
    before_deposit = eth_provider.get_l1_balance(eth_token, EthBlockParams.LATEST)
    print(before_deposit)

    print(f"Before: {before_deposit}")
    l1_tx_receipt = eth_provider.deposit(token=Token.create_eth(),
                                         amount=wei_amount,
                                         gas_price=gas_price)
    
    print(l1_tx_receipt)
    print(l1_tx_receipt.hex())
    # TODO: when L2 tx

    after = eth_provider.get_l1_balance(eth_token, EthBlockParams.LATEST)
    print(f"After : {after}")

    print(f"Tx status: {l1_tx_receipt['status']}")


if __name__ == "__main__":
    deposit(0.1)

The output is :

Token(l1_address='0x0000000000000000000000000000000000000000', l2_address='0x000000000000000000000000000000000000800a', symbol='ETH', decimals=18)
1000000000000000000

eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes.  Only got 0 bytes

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

web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?

Returning False when connecting to remote testnet node.

Hi
From what I understand a ZkSyncBuilder instance is basically a Web3 object with an instance of zksync module.
Whenever I want to check if I am connected to the remote L2 zksync testnet node it always returns me False.
Sounds weird cause when I connect to a remote L1 ETH node using HTTPProvider object from Web3 instance it always returns me True.

from zksync2.module.module_builder import ZkSyncBuilder

ZKSYNC_TEST_URL = "https://zksync2-testnet.zksync.dev"
w3 = ZkSyncBuilder.build(ZKSYNC_TEST_URL)
print(w3.is_connected())

Shouldn't this snippet code return me True ?

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.