Git Product home page Git Product logo

hardhat-tracer's Introduction

hardhat-tracer 🕵️

Allows you to see events, calls and storage operations when running your tests.

NOTE: hardhat-tracer v2 is currently in beta. Please see v2-beta branch.

Installation

Step 1: Install the package

npm i hardhat-tracer

Step 2: Add to your hardhat.config.js file

require("hardhat-tracer");

Usage

Test

Just add the --trace or --fulltrace after your test command.

npx hardhat test --trace      # shows logs + calls
npx hardhat test --fulltrace  # shows logs + calls + sloads + sstores
npx hardhat test --trace --opcodes ADD,SUB # shows any opcode specified

Console testing

You can just enable trace some code snippet in your tests:

hre.tracer.enabled = true;
await myContract.doStuff(val2);
hre.tracer.enabled = false;

Trace

You can trace a mainnet transaction and ABIs/artifacts in your project will be used to decode the internal message calls.

npx hardhat trace --hash 0xTransactionHash # works if mainnet fork is on
npx hardhat trace --hash 0xTransactionHash --rpc https://url # must be archive node

Calldata decoder

If you are just looking for a quick decode of calldata or Solidity's Custom Error:

$ npx hardhat decode --data 0x095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ERC20.approve(spender=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, amount=115792089237316195423570985008687907853269984665640564039457584007913129639935)

Address name tags

You can set display names / name tags for unknown addresses by adding new entry to hre.tracer.nameTags object in your test cases, see following example:

hre.tracer.nameTags[this.arbitrager.address] = "Arbitrager";

or can be set in hardhat config

tracer: {
    nameTags: {
        '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266': 'Hunter',
        [someVariable]: 'MyContract',
    },
},

hardhat-tracer's People

Contributors

zemse avatar alcuadrado avatar fvictorio avatar scnale avatar fzeoli avatar wighawag avatar inveker avatar k06a avatar prajwalmore avatar farwayer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.