trufflesuite / ganache-cli-archive

Fast Ethereum RPC client for testing and development. See https://github.com/trufflesuite/ganache for current development.
https://www.trufflesuite.com/ganache
MIT License
3.36k stars 695 forks source link

How to retrieve transaction logs? #806

Closed sfl0r3nz05 closed 3 years ago

sfl0r3nz05 commented 3 years ago

I am running ganache on docker and I need to retrieve transaction errors via web3 and opcode logs in order to perform handling errors.

Context

This is the segment of my docker-compose used to deploy ganache: image As you can see, I am using (--debug) to see the opcodes generated. In this regards, when I forcing an "out of gas" transaction, I can see this information: image In addition, I retrieve this error through the web3, where I guess the name: "o", means " out of gas". image

I would need, to access the information I have debugged through the API or web3.

I would appreciate any ideas.

Your Environment

davidmurdoch commented 3 years ago

You'll want to use debug_traceTransaction for that (see https://geth.ethereum.org/docs/rpc/ns-debug#example-2). Note: ganache doesn't support the tracer option.

The o: looks to be an issue with webpack minifying the name of the class (RuntimeError, I think) into the single letter, o. Calling toString() on an Error object causes the name of the error object to be prepended to the error's message, e.g., new Error("message").toString() === "Error: message".

Let me know if this answers your questions!

sfl0r3nz05 commented 3 years ago

Thanks, @davidmurdoch, debug_tracerTransaction is exactly what I would need.

One option could be, collect ganache logs, and once I have recovered the hash of the failed transaction, via web3 catch error, recover values which normally, "debug.traceTransaction" would return. Does this make sense to you? Any idea to collect these logs? I am thinking, in something similar to this, i.e., definition of a place to collect transactions (e.g.: ganache_data).

image

Thanks in advance.

davidmurdoch commented 3 years ago

Why can't you just use debug_traceTransaction?

sfl0r3nz05 commented 3 years ago

@davidmurdoch, I didn't understand what you meant by the tracer option. I see it now. Thank you very much.