Get revert reason from sendSignedTransaction

I'm running a Hyperledger Besu private chain and making a sendSignedTransaction call from an Express server.

        try {
            let tx = {
                from: fromAccount,
                to: this.contract.options.address,
                gas: 2000000,
                gasPrice: "0",
                value: 0,
                data: await this.contract.methods
                    .method().encodeABI()
            };
    
            console.log(tx);
            console.log("signing transaction");
            let signedTx = await this.web3.eth.accounts.signTransaction(tx, privateKey);
            console.log("transaction signed");
            let result = await this.web3.eth.sendSignedTransaction(signedTx.rawTransaction)
            console.log(result);
        }
        catch (e) {
            console.log(e);
        }

The transaction is reverting and being caught, but I'm not sure how to get the revert reason. I've tried setting contract.handleRevert as well as other solutions from search engines, but all the other solutions assume you are using sendTransaction,call, or send from the front end. Per the web3.js docs, handleRevert doesn't work for sendSignedTransaction (https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#handlerevert) and the error returns as one long string:

Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0xcb93d98a8d6f7c329dfd0cdb7d2fc421147ae077765e63263c794eb43aaa6263",
  "blockNumber": 560179,
  "contractAddress": null,
  "cumulativeGasUsed": 35348,
  "from": fromAddress,
  "gasUsed": 35348,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": contractAddress,
  "transactionHash": "0xfbd9b755aa71d823640c0f719d358ef9c7d81362a901ec2901fba5f188a4a310",
  "transactionIndex": 0,
  "revertReason": "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000204552433737373a2073656e6420746f20746865207a65726f2061646472657373"
}
    at Object.TransactionError (/home/blockchain-dev/Documents/blockchain-app/server/node_modules/web3-core-helpers/src/errors.js:96:21)
    at Object.TransactionRevertedWithoutReasonError (/home/blockchain-dev/Documents/blockchain-app/server/node_modules/web3-core-helpers/src/errors.js:108:21)
    at /home/blockchain-dev/Documents/blockchain-app/server/node_modules/web3-core-method/src/index.js:482:48
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  receipt: {
    blockHash: '0xcb93d98a8d6f7c329dfd0cdb7d2fc421147ae077765e63263c794eb43aaa6263',
    blockNumber: 560179,
    contractAddress: null,
    cumulativeGasUsed: 35348,
    from: fromAccount,
    gasUsed: 35348,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    to: contractAddress,
    transactionHash: '0xfbd9b755aa71d823640c0f719d358ef9c7d81362a901ec2901fba5f188a4a310',
    transactionIndex: 0,
    revertReason: '0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000204552433737373a2073656e6420746f20746865207a65726f2061646472657373'
  }
}

I also tried running a hex to ascii converter on the revertReason hex code and the value was not readable.

I'd like to be able to get the revert reason for a sendSignedTransaction call.


You can decode the revertReason using web3.utils.hexToAscii().

const reason = web3.utils.hexToAscii('0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000204552433737373a2073656e6420746f20746865207a65726f2061646472657373');

Returns

Ãy   ERC777: send to the zero address

Note: The first two characters look like UTF BOM, but hexToUtf8() fails to decode the string (and the rest of the string is really ASCII, not UTF).