zemse/hardhat-tracer

npx hardhat run support

Opened this issue · 3 comments

Hey, thanks for the great plugin!
Would it be possible to add support of --trace to hardhat run command?

zemse commented

I'll explore if this can be supported. But for now this workaround can be used:

import hre from 'hardhat'; 
import { wrapHardhatProvider } from "hardhat-tracer/dist/src/wrapper";

wrapHardhatProvider(hre);
hre.tracer.enabled = true;
hre.tracer.verbosity = 3; // prints all txs, use 1 if you need only failed printings

async function main() {
  ...
}

I need this feature too, It would be very usefull.

Maybe this is a limitation of hre/ethers but provided workaround show traces only for successfull calls. If call ended up with a revert, no traces are shown. but with npx hardhat trace --hash all traces are shown

as a quick and dirty workaraund I use

`
try {
let tx = await signer.sendTransaction(params);
...
} catch (err) {
console.log(err.data.message,err.data.txHash);

    printDebugTraceOrLogs(err.data.txHash,{
        artifacts: hre.artifacts,
        tracerEnv: hre.tracer,
        provider: hre.network.provider,
        nameTags: {},
      });
}

`

zemse commented

Maybe this is a limitation of hre/ethers but provided workaround show traces only for successfull calls

Yeah this was the case in V1 because it relied on debug_traceTransaction. But in v2 it hijacks the VM to get the execution info and now you do not need to do this. --trace would print all successful and failed while --traceError would only print the failed transactions or calls for you. To use v2 you can just install latest version npm i hardhat-tracer@latest.