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.

up vote 11 down vote accepted

(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.

  • 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. [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? – The Officious 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. – The Officious BokkyPooBah Dec 19 '16 at 14:04
  • 1
    Have you added admin to the --rpcapi option? – The Officious BokkyPooBah Dec 19 '16 at 14:35

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.