# @atixlabs/hardhat-time-n-mine 中文文档

规范地址：https://npmcn.com/package/%40atixlabs/hardhat-time-n-mine/

版本：0\.0\.5
npm 元数据更新时间：2022-04-04T16:04:38.772Z
中文译文更新时间：2026-11-07T02:09:32.728Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40atixlabs/hardhat-time-n-mine
原文对照：https://npmcn.com/package/%40atixlabs/hardhat-time-n-mine/?lang=original
项目主页：https://github.com/atixlabs/hardhat-time-n-mine#readme
源码仓库：https://github.com/atixlabs/hardhat-time-n-mine

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：27.2 kB，29 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- peer 依赖：hardhat ^2\.0\.0
- 首次发布：2021-06-25T02:27:22.161Z
- 最新版本发布：2021-08-16T19:17:45.917Z
- 近 30 天下载量：2661（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 0 个）

## 中文简介

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

## 安装

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

也可以使用：`pnpm add @atixlabs/hardhat-time-n-mine`、`yarn add @atixlabs/hardhat-time-n-mine`、`bun add @atixlabs/hardhat-time-n-mine`

## README

# 硬帽子时间 -n -地雷

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

[哈达特](https://hardhat.org/) 插件实例 .

## 什麽

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

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

## 安装

要安装它,你只需要

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

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

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

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

```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
```

我们正在使用 [分钟](https://www.npmjs.com/package/ms) 来解析三角洲,如果它不是一个数字,那么你可以使用其中的任何一种格式.

实例:

-   `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
```

我们正在使用 [分钟](https://www.npmjs.com/package/ms) 来解析三角洲,如果它不是一个数字,那么你可以使用其中的任何一种格式.

实例:

-   `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 是什么？

操纵时间和地雷块的 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 和提交记录判断。

