hardhat中使用console

关于hardhat中console的使用(solidity debug)

1.简单参考demo如下:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;

import "hardhat/console.sol";
// import * as hht from "hardhat/console.sol";

contract Test {
    
    
  function test() public view returns (bool) {
    
    
    console.log("test solidity console");
    console.logBytes4(0x095ea7b3);
    // hht.console.log("test other");
    return true;
  }
}

2.使用说明:
a.必须是hardhat框架
b.只能在hardhat本地local节点才能运行
c.打印结果会在本地节点控制台中展示
d.如果遇到直接使用"hardhat/console.sol"不支持的情况,可以通过重命名解决,如果满足所有条件还提示异常不用理会,编译合约如果能通过即表示可以使用

3.其余log参考
https://github.com/NomicFoundation/hardhat/blob/main/packages/hardhat-core/console.sol

猜你喜欢

转载自blog.csdn.net/qq_43234632/article/details/128625298