Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to deploy contract from web3.py #7900

Open
maoudia-via opened this issue Nov 21, 2024 · 1 comment
Open

Unable to deploy contract from web3.py #7900

maoudia-via opened this issue Nov 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@maoudia-via
Copy link

maoudia-via commented Nov 21, 2024

Steps to Reproduce

I used the following code to deploy a smart contract on Besu with a gasless setup:

def deployed_contract():
    w3 = get_provider()
    contract = get_contract()
    owner_account = get_contract_owner_account()
    transaction = contract.constructor().build_transaction(
        {
            "nonce": w3.eth.get_transaction_count(owner_account.address),
            "gas": 1000000,
            "gasPrice": 0,
            "chainId": CHAIN_ID,
        }
    )
    signed_transaction = owner_account.sign_transaction(transaction)
    tx_hash = get_provider().eth.send_raw_transaction(
        signed_transaction.raw_transaction
    )
    
    try:
        tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)
    except Exception as e:
        print(f"Error in deploy transaction {e}")
        raise
    assert tx_receipt.status == 1, f"Contract deployment failed {tx_receipt.logs}"
    deployed_contract = w3.eth.contract(
        address=tx_receipt.contractAddress, abi=contract.abi
    )
    print(f"contract deploy receipt items {tx_receipt.items()}")
    return deployed_contract

The contract itself is built via a solc command and I was able to compile and deploy it on the quorum explorer (contracts tab).

Expected behavior: The transaction receipt should have a status equal to 1.

Actual behavior: The transaction receipt has a status equal to 0 and I am unable to interact with the contract functions properly. I am able to interact.with the smart contract if I deploy it using quorum explorer.

Frequency: Every time

Logs

Transaction receipt attributes:

AttributeDict({'blockHash': HexBytes('0xea1dbc47478ad8775e9ac727cbe9471136fbdab7a4d24ca2788feb4f4af0574d'), 'blockNumber': 97575, 'contractAddress': '0x200070cfd443C125b9E8D472c09D1C1EECEae107', 'cumulativeGasUsed': 1000000, 'from': '0x9Bf048626634F6984793727C13aA73d6D5c06c97', 'gasUsed': 1000000, 'effectiveGasPrice': 0, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'status': 0, 'to': None, 'transactionHash': HexBytes('0xa0ec6ff133f3fd036c785cc8d594b11f7128ee8a29c13844fdc5b079a35127ab'), 'transactionIndex': 0, 'type': 0}).status

Versions (Add all that apply)

web3 7.5.0

Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information)

  • Solidity version :
    solc, the solidity compiler commandline interface
    Version: 0.8.28+commit.7893614a.Darwin.appleclang
@maoudia-via maoudia-via added the bug Something isn't working label Nov 21, 2024
@siladu
Copy link
Contributor

siladu commented Nov 26, 2024

Hi @maoudia-via if the contract was successfully deployed to Besu using the quorum explorer then it sounds like the issue is related to your web3 code (or the library itself) rather than Besu.

One thing you could try is running Besu with --logging=DEBUG (or TRACE if necessary) to see the request that actually ends up in Besu and compare between the quorum explorer and web3.
You're probably looking for eth_sendRawTransaction.
Increasing the logging may also give you some details about why the transaction is failing

Other things you could check are that the fork version of your network (berlin, london, etc) matches the solc evm version.
If you're on london fork or later, then you may try sending a 1559 transaction: it looks like your code is using a frontier transaction since it has gasPrice instead of maxFeePerGas and maxPriorityFeePerGas.

Perhaps some libraries always expect a non-zero gas price so maybe there's some assumptions in the web3 library about that? e.g. the library adds a non-zero price automatically but the sender has no funds to send. One way to test this would be to fund the account.

Finally, you can simulate transactions with eth_call https://besu.hyperledger.org/public-networks/reference/api#eth_call which might give you more info about the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants