hardhat中使用console

  • Post author:
  • Post category:其他




关于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



版权声明:本文为qq_43234632原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。