9

Following answer (https://ethereum.stackexchange.com/a/9437/4575) [ 1 ] guide us to call debug_trace through using geth:

As documented in debug.traceTransaction(...), you can only access this API call using the geth JavaScript console or the JSON-RPC API. There is no web3 API that I know of. There are some unofficial extension web3 APIs, but I don't know if debug.traceTransaction is supported by these. Looks like you have to use JSON-RPC to access this data.

but I was wondering is it possible to call debug_Transaction inside nodejs ?

I tried the steps on https://ethereum.stackexchange.com/a/9462/4575 [ 2 ] but it seems does not work for me and this answer seems contradict with the previous answer I have lined on [ 1 ].

var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

web3.currentProvider.sendAsync({
        method: "debug_traceTransaction",
        params: ['<transaction_id>', {}],
        jsonrpc: "2.0",
        id: "2"
    }, function (err, result) {
        console.log( result );
    });

Output result:

{ jsonrpc: '2.0',
  id: '2',
  error:
   { code: -32601,
     message: 'The method debug_traceTransaction does not exist/is not available' } }

Thank you for your valuable time and help.

alper
  • 8,395
  • 11
  • 63
  • 152

1 Answers1

12

(Here is the same response as the one I added to the question referenced above)

If I start geth using the following command line:

Iota:~ user$ geth --rpc console

And I try to execute the following curl command:

Iota:~ user$ curl localhost:8545 -X POST --header 'Content-type: application/json' --data '{"jsonrpc":"2.0", "method":"debug_traceTransaction", "params":["0x3684f071b34da1116282ee88a106a8f2a266d273ef7d8964957f65128fb58d77", {}], "id":1}'

I get the following result:

{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"The method debug_traceTransaction does not exist/is not available"}}

If instead I start geth with the following command:

Iota:~ user$  geth --rpc --rpcapi "eth,net,web3,debug" console

And I run the same curl command, I get the transaction trace as shown below:

{"jsonrpc":"2.0","id":1,"result":{"gas":45480,"returnValue":"0000000000000000000000000000000000000000000000000000000000000001","structLogs":[{"pc":0,"op":"PUSH1","gas":76741,"gasCost":3,"depth":1,"error":null,"stack":[],"memory":null,"storage":{}},{"pc":2,"op":"PUSH1","gas":76738,"gasCost":3,"depth":1,"error":null,"stack":["0000000000000000000000000000000000000000000000000000000000000060"],"memory":null,"storage":{}},{ ...

Also note that you cannot get the debug_traceTransaction information from the section of the blockchain that you have --fast synced.

So, you just need to add the --rpcapi "eth,net,web3,debug" command line option.



Update Responding To Comment Below

@Avatar, please check out https://github.com/tjade273/web3_ipc/blob/master/index.js#L328-L335 . See also Why can't I connect by IPC? and Connect to node via IPC as these use the same library.

BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
  • 1
    I do approve your answer and it works through using geth, and I appreciated your answer. My question is about (I just wanted to double check) , does your answer means that am I require to use geth since it is not possible to call debug_traceTransaction through nodejs or other applications? The reason I need to call debug_traceTransaction is related to your answer to check transaction status. [http://ethereum.stackexchange.com/a/6011/4575] – alper Dec 19 '16 at 13:39
  • From your nodejs result, which matches my JSON-RPC result when I don't have the --rpcapi ...debug option, it seems that your nodejs call to debug_traceTransaction is getting to geth via JSON-RPC but geth is returning the message that the debug_traceTransaction call is unavailable. So theoretically you should be able to access debug_traceTransaction via nodejs. Am I missing something else? – BokkyPooBah Dec 19 '16 at 13:46
  • 1
    Just as note, on the background geth works as you recommended and it works that geth returns me the debug_traceTransaction information. So the issue might be related to the way I am calling debug_traceTransaction inside nodejs, where nodejs unable to find/call debug_traceTransaction function. – alper Dec 19 '16 at 13:53
  • Updated answer with web3_ipc which includes the call to debug_traceTransaction. – BokkyPooBah Dec 19 '16 at 14:04
  • I have tried to example related to Example of RPC Connection on https://github.com/tjade273/web3_ipc/blob/master/README.md: I am facing with Error: The method admin_datadir does not exist/is not available. – alper Dec 19 '16 at 14:29
  • 1
    Have you added admin to the --rpcapi option? – BokkyPooBah Dec 19 '16 at 14:35