How To Trace Solidity Errors On Websocket (Hardhat)?

If I had hair, I’d be tearing it out trying to get to the bottom of this.

I have a hardhat javascript bot to analyze and make trades on ethereum that connects via websocket on web3js.

I’m currently forking the chain to work with any errors in my smart contract code and my trade execution functions on javascript.

The problem is that the only solution I can find to trace errors is hardhat-trace, but that requires a http RPC. I really can’t use a http due to the way my bot is built.

Is there any way I can error handle while using websockets?

For your specific use case I don’t think you’ll be able to use hardhat-trace at all for your production environment. It sounds like your problem is actually detecting the errors and handling them in your websocket connection, is that right?

I’d look at these few options.

  1. Event Listeners for Error Handling: Web3.js provides event listeners that you can use to monitor for errors. For example, you can listen to the error event on your websocket provider to catch and handle errors globally.
  2. Custom Error Handling Logic: Develop a custom error handling mechanism that decodes and interprets the error messages returned by Ethereum. This can be particularly useful for handling revert errors, which can provide insight into why a transaction failed.
  3. Use of Decoders: Tools like ethers.js provide utilities for decoding error messages and logs from transactions. Even if you prefer web3.js for its websocket support, you might integrate ethers for its error parsing capabilities in specific scenarios.

Thank you SO much. Follow up question:

With respect to decoders and ethers - I had thought that ethers and web3js didn’t like to live in the same space - do they not cannibalize each other in the sense that the existence of each on a script might cause overlap?

Personally I haven’t tried both at the same time, but with my knowledge of how they work they shouldn’t clash with each other, especially if they aren’t trying to do the same thing. Like you don’t have a web3 provider and an ethers provider both trying to make websocket connections and trying to pass them back and forth with one another.

Web3js probably has decoders, but I personally haven’t used the package in several years so I can’t speak to that specifically, but I would be surprised if they didn’t have them.