Set the nameTags before tracing a transaction?
Closed this issue · 2 comments
Hello everyone,
I have already tried the command npx hardhat test --fulltrace
with setting addresses nameTags
.
It works great and highly readable. This tool truly helps me a lot!
However, when I tried to run a script with npx hardhat run
, nameTags
doesn't work.
Here are the descriptions of what I tried:
(1) I have set up a Hardhat Network with mainnet forking mode.
(2) Because I only have Alchemy free account, I cannot use the debug API (e.g., debug_traceTransaction
).
(3) As a result, I set up a Hardhat Network with forking. Then, I ran another project which is connected to the Hardhat Network and sent transactions to that network.
(4) When I tried to use npx hardhat trace --hash 0x...
command, the addresses cannot display with the nameTags
.
For example, the directory structure: (omitted trivial folders/files)
├── 📂 hardhat_network_w_forking
└── 📂 another_project
├── 📄 contract.sol
├── 📄 hardhat.config.js
└── 📄 script.js
(1) I ran npx hardhat --network "hardhat" node
command in the 📂hardhat_network_w_forking
.
The default JSON-RPC URL is http://127.0.0.1:8545
.
(2) hardhat.config.js
in the 📂another_project
:
require("hardhat-tracer");
module.exports = {
...
mynet: {
url: "http://127.0.0.1:8545",
...
};
(3) contract.sol
in the 📂another_project
:
import "WETH9-abi.sol";
contract C {
uint256 public dummy;
function foo() public {
WETH9(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).balanceOf(address(this));
dummy = 3; // Let foo() be a non read-only function
}
(4) script.js
in the 📂another_project
:
async function main() {
... // Deploy contract C
const weth9_address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
hre.tracer.nameTags[weth9_address] = "WrappedEther";
... // Invoke C.foo() by sending a transaction to "mynet"
}
main();
(5) Finally, I ran the following commands in the 📂another_project
.
$ npx hardhat --network "mynet" run script.js
...
"transactionHash": "0xdf85...",
...
$ npx hardhat --network "mynet" trace --hash "0xdf85..."
CALL C.foo()
STATICCALL <UnknownContract 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2>.balanceOf(owner=0x5302...) => (0)
(6) But, if I ran the same script with npx hardhat test --trace
, I would get:
CALL C.foo()
STATICCALL WrappedEther.balanceOf(owner=0x5302...) => (0)
In short, hre.tracer.nameTags[weth9_address] = "WrappedEther";
doesn't work when running the combination of npx hardhat run
and npx hardhat trace --hash "0x..."
.
Could anyone tell me how should I do to solve this problem?
Many thanks.
Just added the ability to specify nameTags
in config available in hardhat-tracer@1.1.0-rc.4
. So the addresses specified in config should be available in the scripts as well as the trace task. Let me know if it works or if any issue.
tracer: {
nameTags: {
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266': 'MyContract',
[wethAddress]: 'WrappedEther',
},
},
Awesome!
The functionalities work pretty well in hardhat-tracer@1.1.0-rc.6
.
I also found that if I have compiled the contracts (which are involved in the transaction), the output result would be automatically converted into contract ABI's format.🤩