Web3 Contract Deployment Error: VM Exception 'Revert' during Transaction Processing

58 Views Asked by At

Web3 Contract Deployment Error - Execution Reverted

I am encountering an issue while deploying a smart contract using Web3. The deployment process triggers an error leading to contract execution being reverted.

Problem Description: Upon attempting to deploy a smart contract using Web3, the deployment process fails, and the transaction is reverted. The error message suggests a VM Exception during transaction processing with the specific message: "revert."

Code =

import solcx
from web3 import Web3
import json

def compile_source_file(file_path):
    compiled_file = solcx.compile_files([file_path],
                                        output_values=["abi", "bin-runtime"],
                                        solc_version="0.8.0")
    return compiled_file

def deploy_smart_contract(compiled_details):
    abi = next(iter(compiled_details.values()))["abi"]
    bytecode = next(iter(compiled_details.values()))["bin-runtime"]
    
    w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))
    account = w3.eth.accounts[0]

    Greeter = w3.eth.contract(abi=abi, bytecode=bytecode)

    tx_hash = Greeter.constructor().transact()
    tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)

    contract = w3.eth.contract(
        address=tx_receipt.contractAddress,
        abi=abi
    )

    greeting_value = contract.functions.greet().call()
    print("Greeting Value:", greeting_value)


sol_file_path = "contract.sol"
sol_compiled_file = compile_source_file(sol_file_path)
deploy_smart_contract(sol_compiled_file)


Error -

Traceback (most recent call last):
  File "D:\Accumulate\new_02_02\document_2.py", line 34, in <module>
    deploy_smart_contract(sol_compiled_file)
  File "D:\Accumulate\new_02_02\document_2.py", line 20, in deploy_smart_contract
    tx_hash = Greeter.constructor().transact()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\eth_utils\decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\contract\contract.py", line 624, in transact
    return self.w3.eth.send_transaction(self._get_transaction(transaction))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\eth\eth.py", line 381, in send_transaction
    return self._send_transaction(transaction)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\module.py", line 75, in caller
    result = w3.manager.request_blocking(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\manager.py", line 325, in request_blocking
    response = self._make_request(method, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\manager.py", line 213, in _make_request
    return request_func(method, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\middleware\gas_price_strategy.py", line 100, in middleware
    return make_request(method, (transaction,))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\middleware\formatting.py", line 126, in middleware
    response = make_request(method, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\middleware\attrdict.py", line 43, in middleware
    response = make_request(method, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\middleware\formatting.py", line 126, in middleware
    response = make_request(method, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\middleware\formatting.py", line 126, in middleware
    response = make_request(method, params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\middleware\buffered_gas_estimate.py", line 40, in middleware
    hex(get_buffered_gas_estimate(w3, transaction)),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\_utils\transactions.py", line 154, in get_buffered_gas_estimate
    gas_estimate = w3.eth.estimate_gas(gas_estimate_transaction)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\eth\eth.py", line 311, in estimate_gas
    return self._estimate_gas(transaction, block_identifier)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\module.py", line 75, in caller
    result = w3.manager.request_blocking(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\manager.py", line 326, in request_blocking
    return self.formatted_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\manager.py", line 287, in formatted_response
    apply_error_formatters(error_formatters, response)
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\manager.py", line 104, in apply_error_formatters
    formatted_resp = pipe(response, error_formatters)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cytoolz\\functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz\\functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "D:\Accumulate\new_02_02\env\Lib\site-packages\web3\_utils\contract_error_handling.py", line 154, in raise_contract_logic_error_on_revert  
    raise ContractLogicError(f"execution reverted: {message}", data=data)
web3.exceptions.ContractLogicError: execution reverted: VM Exception while processing transaction: revert

I expected the smart contract deployment to be successful without encountering any exceptions. The goal was to have a fully functional contract deployed on the specified network with the given ABI and bytecode.

I'm seeking assistance in understanding and resolving the VM Exception during transaction processing, specifically the "revert" message.

0

There are 0 best solutions below