zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
341 stars 35 forks source link

Programatically access trace from a standalone hardhat node #62

Closed piwonskp closed 5 months ago

piwonskp commented 7 months ago

Use case

I would like to run a standalone node using hardhat node, deploy a contract from a script on it and access the trace from within the same script.

Suggested solution

Custom RPC endpoint(s) could be implemented to allow calling functions such as tracer.lastTrace() remotely.

Would you be willing to accept a PR implementing such a solution?

zemse commented 7 months ago

Custom RPC endpoint(s) could be implemented to allow calling functions such as tracer.lastTrace() remotely. Would you be willing to accept a PR implementing such a solution?

Sure, but how are you planning to implement this? Since to add an RPC method, I believe you need to modify the hardhat repository. Is it possible to add an RPC method to hardhat network via a plugin? Then this makes sense.

Some info that might be useful: this plugin hijacks the ethereumjs VM object which does all the low-level evm operations and collects the relevant trace data as tx keeps on executing on the VM and finally makes it available to consume through the lastTrace(). However, this cannot work if you are using an rpc node (even if it is hardhat node over localhost, it is possible to hh node --trace but it only works in the node terminal, not in your tests).

piwonskp commented 7 months ago

Yes, it is possible. I plan to override _send method of provider here. Hardhat-tracer already implements a custom provider so I guess it will be easy