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

Add support for custom errors or provide full RPC response if transaction is reverted #2793

Closed
Shchepetov opened this issue Jan 25, 2023 · 1 comment · Fixed by #2922
Closed

Comments

@Shchepetov
Copy link

  • Version: 6.0.0b9
  • Python: 3.10.9
  • OS: osx

What was wrong?

I need to call a contract method and get revert data

from web3 import Web3
w3 = Web3(Web3.HTTPProvider("https://eth-goerli.public.blastapi.io"))
contract = w3.eth.contract(address=address, abi=abi)
contract.functions.alwaysReverts().call()

Unfortunately the exception raised with call() method provides no information about triggered custom error and the data passed as the error parameters:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  ...
    File "/Users/alexander/Desktop/FastAPI/venv/lib/python3.10/site-packages/web3/_utils/method_formatters.py", line 636, in     raise_solidity_error_on_revert
    raise ContractLogicError(response["error"]["message"])
web3.exceptions.ContractLogicError: execution reverted

If we look at the variable response used to raise the exception, we see that this data is contained in response["error"]["data"]

>>> response
{'jsonrpc': '2.0', 'id': 1, 'error': {'code': 3, 'message': 'execution reverted', 'data': '0x8f046edb0000000000000000000000000000000000000000000000000000000063d1a1a400000000000000000000000000000000000000000000000000000000000003ff'}}

But it isn't used in the exception and there is no access to raw response data but there should be a proper way to get it

@kclowes
Copy link
Collaborator

kclowes commented Jan 25, 2023

Yeah, agreed. Thanks for raising the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants