diff --git a/brownie/network/middlewares/hardhat.py b/brownie/network/middlewares/hardhat.py index fd1368310..47ed860f4 100644 --- a/brownie/network/middlewares/hardhat.py +++ b/brownie/network/middlewares/hardhat.py @@ -17,12 +17,17 @@ def process_request(self, make_request: Callable, method: str, params: List) -> result = make_request(method, params) # modify Hardhat transaction error to mimick the format that Ganache uses - if method == "eth_sendTransaction" and "error" in result: + if method in ("eth_call", "eth_sendTransaction") and "error" in result: message = result["error"]["message"] if message.startswith("VM Exception") or message.startswith("Transaction reverted"): - txid = self.w3.eth.getBlock("latest")["transactions"][0] + if method == "eth_call": + # ganache returns a txid even on a failed eth_call, which is weird, + # but we still mimick it here for the sake of consistency + txid = "0x" + else: + txid = self.w3.eth.getBlock("latest")["transactions"][0].hex() data: Dict = {} - result["error"]["data"] = {txid.hex(): data} + result["error"]["data"] = {txid: data} message = message.split(": ", maxsplit=1)[-1] if message == "Transaction reverted without a reason": data.update({"error": "revert", "reason": None})