Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to visit traces happened inside transaction? #29

Open
k06a opened this issue Feb 18, 2023 · 1 comment
Open

How to visit traces happened inside transaction? #29

k06a opened this issue Feb 18, 2023 · 1 comment

Comments

@k06a
Copy link
Contributor

k06a commented Feb 18, 2023

Imagine I wish to check gas_used by 2 traces inside transaction using v2?

For example, I am writing gas tests for Limit Order Protocol, and wish to check gas used by protocol, so I am going to calculate

tx.gas_used - tokenA.transferFrom.gas_used - tokenB.transferFrom.gas_used
@zemse
Copy link
Owner

zemse commented Feb 18, 2023

There could be a better API, but currently, the particular value can be taken from the tx trace object.

import {CallItem} from 'hardhat-tracer'

// can be a read call, estimate gas, write tx
await contract.method()

// traverse to the right location in the trace and extract the gasUsed
const trace1 = hre.tracer.lastTrace()!;
const callItem = trace1.top?.children?.[0].children?.[0] as CallItem;
const gasUsed = callItem.params.gasUsed!;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants