Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hardhat Ignition:可追踪的模块化部署

Ignition 用模块描述部署依赖关系,并保存执行记录。相比在脚本里手动按顺序发送交易,模块化部署更容易重试、复用参数和审查变更。

import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

export default buildModule("CounterModule", (m) => {
  const counter = m.contract("Counter");
  return { counter };
});

执行部署:

npx hardhat ignition deploy ignition/modules/Counter.ts --network sepolia

生产部署前确认:

  • 网络名称和 chain ID 正确。
  • 构造参数来自版本化配置,而不是临时命令行输入。
  • 模块执行记录、合约地址和交易哈希已保存。
  • 升级模块明确代理管理员、实现地址和初始化调用。
  • 失败后先检查已完成的部署步骤,再决定是否重试或恢复。

Ignition 记录的是部署过程,不会自动证明合约逻辑安全;部署后仍需验证源码、检查权限并运行链上状态核对脚本。