How to get the revert reason of a failed transaction

Using the infura plateform and the web3j library](, how do I get the revert reason of a failed transaction?

If I understand it correctly, there are two ways to get the revert reason:
1- enable this feature, so that the TransactionReceipt contains this information. The node must support this option.

2- make an extra call to get this information. No need for a special node supporting this feature.

Is this correct?

What value should I pass into the data and revertReasonCallEnabled parameters?

public call(RemoteFunctionCall call) {
  try {
  } catch (TransactionException e) {  
    System.out.println("revert reason: " + e.getTransactionReceipt.get.getRevertReason()); // returns null 
    String data = ???                   // << what value goes here?
    Boolean revertReasonCallEnabled =   // << what value goes here?
    System.out.println("revert reason extracted: " + RevertReasonExtractor.extractRevertReason(receipt, data, web3j, revertReasonCallEnabled))

Should it be as follows?

String data = e.getTransactionReceipt.get.getRevertReason()

However, this returns null for my specific remote call;

I’ve tried both with revertReasonCallEnabled = true and revertReasonCallEnabled = false, but extractRevertReason always returns N/A.

Hi @dportabella, I believe this is a question for the web3js team, as the revert reason is a web3 method. You could also try npm eth-revert-reason as well to see if that works for you.

I see, i could successfully get the revert reason with the npm package you mention, thanks.