Geth v1.8.0 supports new way of fetching transactions via IPC or WebSockets (debug_subscribe). There is an example in release notes which works almost perfectly:

$ nc -U /work/temp/rinkeby/geth.ipc
{"id": 1, "method": "debug_subscribe", "params": ["traceChain", "0x0", "0xfff", {"tracer": "callTracer"}]}


{"jsonrpc":"2.0","method":"debug_subscription","params": {"subscription":"0xe1deecc4b399e5fd2b2a8abbbc4624e2","result":{"block":"0x37","hash":"0xdb16f0d4465f2fd79f10ba539b169404a3e026db1be082e7fd6071b4c5f37db7","traces":[{"from":"0x31b98d14007bdee637298086988a0bbd31184523","gas":"0x0","gasUsed":"0x0","input":"0x","output":"0x","time":"1.077µs","to":"0x2ed530faddb7349c1efdbf4410db2de835a004e4","type":"CALL","value":"0xde0b6b3a7640000"}]}}}
{"jsonrpc":"2.0","method":"debug_subscription","params": {"subscription":"0xe1deecc4b399e5fd2b2a8abbbc4624e2","result":{"block":"0xf43","hash":"0xacb74aa08838896ad60319bce6e07c92edb2f5253080eb3883549ed8f57ea679","traces":[{"from":"0x31b98d14007bdee637298086988a0bbd31184523","gas":"0x0","gasUsed":"0x0","input":"0x","output":"0x","time":"1.568µs","to":"0xbedcf417ff2752d996d2ade98b97a6f0bef4beb9","type":"CALL","value":"0xde0b6b3a7640000"}]}}}

However even though block hashes are included, the transaction hashes are not.

I wanted to adapt the sources as the release notes suggest, but I don't know how I can use them... Do I need to recompile geth or is there a way I can install my tracer via JS interface?

  • 1
    I’m really looking forward to this answer. Feb 19 '18 at 21:22
  • 3
    Try passing your javascript code instead of the tracer name "params": [..., {"tracer": "<javascript code goes here>"}]. From this github.com/ethereum/go-ethereum/blob/master/eth/tracers/… it appears it is used as code if the name doesn't match one of the internal tracers.
    – Ismael
    Feb 19 '18 at 21:48
  • @Ismael Nice find, thanks! Can you post it as answer so we have the collection of possible solutions? If nothing else, this sounds like it could work, though the escaping will be challenging I guess... :)
    – johndodo
    Feb 20 '18 at 7:18
  • @Ismael That approach actually works, thanks! If you post it as a separate answer I'd be happy to accept it.
    – johndodo
    Feb 20 '18 at 8:59
  • 2
    @johndodo Trying this is in my TODO list but I didn't have much time. I will be glad if you put a nice answer with an example how to use debug_subscribe so it will benefit others (and myself when I catch up my TODO list).
    – Ismael
    Feb 20 '18 at 16:05

Thanks to @Ismael's comment I managed to deploy my own custom tracker. The idea is to supply JS code instead of the name of the tracer, like this:

$ nc -U /opt/geth1.8/geth.ipc
{"id": 1, "method": "debug_subscribe", "params": ["traceChain", "0x6714a", "0x6714b", {"tracer": "{ step: function(log, db) {}, fault: function(log, db) {}, result: function(ctx, db) { return {ctx: ctx}; }, }"}]}

Note that tracer is an JS object which contains at least 3 functions: step(), fault() and result(). I could find no documentation, so I ended up studying the code and the existing tracers. Basically, step() usually saves some data to an internal variable (this.something) which is later returned by result().

Instead of IPC one can also use WebSockets - the messages are identical in both cases. Hope it helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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