@atixlabs/hardhat-time-n-mine

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

Hardhat plugin to manipulate time and mine blocks

原始使用文档
文档目录14 节
  1. What
  2. Installation
  3. Required plugins
  4. Tasks
  5. mine
  6. increaseTime
  7. setTimeIncrease
  8. setTimeNextBlock
  9. setTime
  10. Environment extensions
  11. Configuration
  12. Usage
  13. Contributing
  14. Future work

hardhat-time-n-mine

This plugin will help you manipulate time and mine blocks while testing and while using the hardhat node to develop any type of DApp.

Hardhat plugin example.

What

This plugins adds some tasks to manipulate the timestamp in the future blocks if you are using hardhat node, it will help you develop DApps that are time dependent without waiting time to actually elapse.

As well as adding said tasks it also extends the HardhatRuntimeEnvironment with the same tasks in a function format so to let you use it in a JS/TS environment(being it automated tests, or your own scripts and tasks).

Installation

To install it you just need

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

Import the plugin in your hardhat.config.js:

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

Or if you are using TypeScript, in your hardhat.config.ts:

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

Required plugins

This plugin does not require any other plugin, it just needs you to install Hardhat ^2.0.0(has been tested with 2.4.0).

Tasks

This plugin adds the tasks explained in the following subsections. Note that you MUST use the --network localhost if you are running the node locally(or any other network with a defined url that points to your node).

mine

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

increaseTime

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

We are using ms to parse the delta if it is not a number, so you can use any of those formats.

Examples:

  • hardhat increaseTime 10: Increases ten seconds
  • hardhat increaseTime 1d: Increases a day
  • hardhat increaseTime "1 week": Increases a week
  • hardhat increaseTime 1y: Increases a year

setTimeIncrease

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

We are using ms to parse the delta if it is not a number, so you can use any of those formats.

Examples:

  • hardhat setTimeIncrease 10: Increases ten seconds
  • hardhat setTimeIncrease 1d: Increases a day
  • hardhat setTimeIncrease "1 week": Increases a week
  • hardhat setTimeIncrease 1y: Increases a year

setTimeNextBlock

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

setTime

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

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding an timeAndMine field which is an object with five functions, namely:

  • mine

  • setTime

  • setTimeNextBlock

  • increaseTime

  • setTimeIncrease

Each of the previously mentioned functions behave like the previously mentioned tasks(but having all of its parameters required) and can be used within your tests/scripts.

Configuration

This plugin does not need any type of extra configuration.

Usage

Once you have the plugin installed and imported in your hardhat.config.js/hardhat.config.ts, you don't have to do anything else, just use the functions in the timeAndMine object or use the defined tasks.

Contributing

Once you installed the repo, you will be able to test the tasks using

npm run test:tasks

(you will have to have a node running for that)

To test the hre methods, you will have to run:

npm run test:hreMethods

You can test all of it using

npm test

You can lint it using:

npm run lint

or

npm run lint:fix

Future work

  • Add ms to parse time deltas
  • Add some date parsing

版本与发布记录

@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 plugin to manipulate time and mine blocks

如何安装 @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 和提交记录判断。