2

Using ethers' waitForTransaction(), getTransactionReceipt() or getTransaction() I can ask for transaction status, but I need to know the cause of error (as this question: How to get transaction failed reason with transaction hash with web3? ) to log it and to take an action over the transaction.

Is still no way by api to know the reason of failure?

1 Answer 1

1

You can 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:

https://polygonscan.com/tx/0x7473494c4d6ac6976193f67e624dbd0963a321dc883ea8d90e115f5246a3b6d2

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/' \
       --compressed

This is the API response:

{
  "hash": "0x7473494c4d6ac6976193f67e624dbd0963a321dc883ea8d90e115f5246a3b6d2",
  "error_message": "ERC20: transfer amount exceeds balance",
  ...
}

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.