5 hardhat一些操作请教

hardhat是否能够指定 blockTime在未来? 比方说fork主网数据后,改时间是在一个星期后,然后模拟调用来测试结果 能否支持这样的功能啊 具体怎么配置?

请先 登录 后评论

最佳答案 2023-02-07 04:57

可以的, 使用 hardhat-network-helpers

代码:

import { time } from "@nomicfoundation/hardhat-network-helpers";

async function main() {
  //  增加时间出块
  await helpers.time.increase(3600);

  // 从新时间戳`newTimestamp`出块  
  await helpers.time.increaseTo(newTimestamp);

  // 设置时间不出块
  await helpers.time.setNextBlockTimestamp(newTimestamp);
}

main();

参考文档:https://hardhat.org/hardhat-network/docs/reference#hardhat-network-methods

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 1 收藏,1202 浏览
  • steel 提出于 2023-02-06 18:03

相似问题