I am using the web3-implementation from python (web3.py) and use the both methods get_transaction and get_transaction_receipt to lookup failed transactions. If the status-field from get_transaction_receipt is 0, i know the transaction has failed.

But if i lookup the transaction with etherscan (or bscscan) i see an error-message (for example: "Fail with error 'Return amount is not enough'".

How can i lookup the transaction with web3 to get access to the content of the error message?

2 Answers 2


As per the current scenario, web3.py doesn't handle this very well, this due to differnt clients handle RPC response in differnt ways (see this issue). However, this is being worked upon very actively (see this issue).

There are few workarounds to accomplish this:

  • use eth-brownie, TransactionReceipt.revert_msg will give the verbose message for revert and TransactionReceipt.dev_revert_msg allows customization for developer specified revert comment

  • use raw RPC call and parse the json


You can also use Tenderly API to do it, here is a sample:

GET https://api.tenderly.co/api/v1/public-contract/{chainId}/tx/{txHash}

Set the chain id and transaction hash in the request path.

By calling this API, you could check the failure reason in the error_message field or in the stack_trace[i].error

Here is a sample failed transaction:


As it is polygon and polygon chain id is 137, you could call this API like this:

curl 'https://api.tenderly.co/api/v1/public-contract/137/tx/0x7473494c4d6ac6976193f67e624dbd0963a321dc883ea8d90e115f5246a3b6d2' \
      -H 'authority: api.tenderly.co' \
      -H 'accept: application/json, text/plain, */*' \
      -H 'accept-language: fa,en-US;q=0.9,en;q=0.8,es;q=0.7' \
      -H 'origin: https://dashboard.tenderly.co' \
      -H 'referer: https://dashboard.tenderly.co/' \

This is the API response:

  "hash": "0x7473494c4d6ac6976193f67e624dbd0963a321dc883ea8d90e115f5246a3b6d2",
  "error_message": "ERC20: transfer amount exceeds balance",
  • FYI this answer was flagged as a duplicate.
    – eth
    Dec 4, 2022 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.