@atixlabs/hardhat-time-n-mine

中文文档
0.0.5发布于 2021/08/17MITTypeScriptCommonJS近 30 天下载 2661

操纵时间和地雷块的 Hardhat 插件

中文使用文档
文档目录14 节
  1. 什麽
  2. 安装
  3. 所需的插件
  4. 任务
  5. 属于我的
  6. 时间
  7. 时间增加
  8. 设置时间NextBlock
  9. 时间
  10. 环境扩展
  11. 配置
  12. 使用量
  13. 捐款
  14. 今后的工作

硬帽子时间 -n -地雷

此插件将帮助您在测试和使用时操纵时间和地雷块 hardhat node 开发任何类型的DApp.

哈达特 插件实例 .

什麽

此插件会添加一些任务来操纵未来块的时间戳, 如果您正在使用的话 hardhat node,它会帮助你开发DApps,这些DApps需要时间而不需要等待时间来真正消散.

除了增加上述任务之外,它还以函数格式扩展了HardhatRuntime Environment的相同任务,以便您能够在JS/TS环境中使用(这是自动测试,或您自己的脚本和任务).

安装

要安装它,你只需要

npm install @atixlabs/hardhat-time-n-mine hardhat

导入您的插件 hardhat.config.js数字 :

require("@atixlabs/hardhat-time-n-mine");

或者,如果你正在使用类型脚本,在您的 hardhat.config.ts数字 :

import "@atixlabs/hardhat-time-n-mine";

所需的插件

此插件不需要其他插件, 它只需要您安装 Hardhat ^ 2. 0.0( 已经用 2.4. 0 测试过) .

任务

此插件添加了以下小节中解释的任务 . 请注意,你必须使用 --network localhost 如果您正在本地运行节点(或者使用指定url指向您节点的任何其他网络) .

属于我的

Usage: hardhat [GLOBAL OPTIONS] mine [--amount <INT>]

OPTIONS:

  --amount	amount of blocks to be mined (default: 1)

mine: mines a single block

For global options help run: hardhat help

时间

Usage: hardhat [GLOBAL OPTIONS] increaseTime delta

POSITIONAL ARGUMENTS:

  delta	difference to add to the current time tracker. Can be a number representing the seconds or a string representing the delta

increaseTime: adds the given delta. NOTICE: this counts 'real' ellapsing time and is not idempotent, we recommend you user setTimeIncrease

For global options help run: hardhat help

我们正在使用 分钟 来解析三角洲,如果它不是一个数字,那么你可以使用其中的任何一种格式.

实例:

  • hardhat increaseTime 10: 增加十秒钟
  • hardhat increaseTime 1d: 增加一天时间
  • hardhat increaseTime "1 week": 增加一周时间
  • hardhat increaseTime 1y: 增加一年

时间增加

Usage: hardhat [GLOBAL OPTIONS] setTimeIncrease delta

POSITIONAL ARGUMENTS:

  delta	difference between the current timestamp and the next. Can be a number representing the seconds or a string representing the delta

setTimeIncrease: makes the next block timestamp increase the given delta with respect to the current block timestamp

For global options help run: hardhat help

我们正在使用 分钟 来解析三角洲,如果它不是一个数字,那么你可以使用其中的任何一种格式.

实例:

  • hardhat setTimeIncrease 10: 增加十秒钟
  • hardhat setTimeIncrease 1d: 增加一天时间
  • hardhat setTimeIncrease "1 week": 增加一周时间
  • hardhat setTimeIncrease 1y: 增加一年

设置时间NextBlock

Usage: hardhat [GLOBAL OPTIONS] setTimeNextBlock time

POSITIONAL ARGUMENTS:

  time	timestamp of the next block 

setTimeNextBlock: set the timestamp of the next block(does not actually mine)

For global options help run: hardhat help

时间

Usage: hardhat [GLOBAL OPTIONS] setTime time

POSITIONAL ARGUMENTS:

  time	timestamp of the next block 

setTime: mines a single block with a given time, effectively setting the time of the blockchain

For global options help run: hardhat help

环境扩展

此插件通过添加一个 timeAndMine 字段 它是一个具有五个功能的物体,即:

  • 属于我的

  • 时间

  • 设置时间NextBlock

  • 时间

  • 时间增加

前面提到的每个函数都与前面提到的任务一样(但需要全部参数),可以在测试/标语中被使用.

配置

此插件不需要任何类型的额外配置 .

使用量

一旦您在 hardhat.config.js/hardhat.config.ts 中安装并导入了插件,您就不必做其他任何工作,只需使用其中的功能 timeAndMine 对象或使用定义的任务.

捐款

一旦安装了回波,您就可以使用

npm run test:tasks

(你必须有一个节点运行)

要测试hre方法, 你必须运行:

npm run test:hreMethods

你可以用它测试所有

npm test

你可以用:

npm run lint

或者说

npm run lint:fix

今后的工作

  • 添加 ms 以解析时间三角洲
  • 添加一些日期解析

版本与发布记录

@atixlabs/hardhat-time-n-mine 共发布 5 个版本,首次发布于 2021/06/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.5latest2021/08/175 年前
0.0.42021/07/165 年前
0.0.32021/06/255 年前
0.0.22021/06/255 年前
0.0.12021/06/255 年前

关于 @atixlabs/hardhat-time-n-mine 的常见问题

@atixlabs/hardhat-time-n-mine 是什么?

操纵时间和地雷块的 Hardhat 插件

如何安装 @atixlabs/hardhat-time-n-mine?

在项目目录运行 npm install @atixlabs/hardhat-time-n-mine,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:hardhat(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atixlabs/hardhat-time-n-mine 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atixlabs/hardhat-time-n-mine 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@atixlabs/hardhat-time-n-mine 可以商用吗?

@atixlabs/hardhat-time-n-mine 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@atixlabs/hardhat-time-n-mine 的下载量有多少?

根据 npm 官方下载统计,@atixlabs/hardhat-time-n-mine 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,661 次,日均约 89 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atixlabs/hardhat-time-n-mine 还在维护吗?

最新版本 0.0.5 发布于 2021/08/17(5 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/06/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。