### Install OpenZeppelin Contracts
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Installs the OpenZeppelin Contracts library, which is necessary for using upgradeable proxy patterns. Use this command in your project's terminal.
```bash
```
--------------------------------
### Parameter File Example (JSON)
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Example of a JSON file used to define module parameters. Supports nested objects for module-specific parameters.
```json
{
"Apollo": {
"name": "Saturn V"
}
}
```
--------------------------------
### Example Deployment Status Output
Source: https://hardhat.org/ignition/docs/guides/deploy.md
This is an example of the output you might see when checking the status of a deployment, including the deployment ID and a success message.
```text
$ npx hardhat ignition deployments
chain-31337
$ npx hardhat ignition status chain-31337
[ chain-31337 ] successfully deployed 🚀
Deployed Addresses
Apollo#Rocket - 0x5fbdb2315678afecb367f032d93f642f64180aa3
```
--------------------------------
### Start a Local Hardhat Node
Source: https://hardhat.org/ignition/docs
Starts a local Hardhat network node. This is a prerequisite for deploying modules to a local environment.
```bash
npx hardhat node
```
```bash
pnpm hardhat node
```
```bash
yarn hardhat node
```
--------------------------------
### Compatible Module Modification Example
Source: https://hardhat.org/ignition/docs/explanations/reconciliation.md
This example shows how modifying a module to express the same outcome in a different way can be compatible with previous deployments.
```javascript
const param = m.getParameter("param");
const foo = m.contract("Foo", [param]);
```
```javascript
const foo = m.contract("Foo", [5]);
```
--------------------------------
### Parameter File Example (Global Parameters)
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Define global parameters using the `$global` key, which are applied to all modules unless overridden by module-specific parameters.
```json
{
"$global": {
"shouldBeAllowed": true
},
"MyModule": {
"shouldBeAllowed": false
}
}
```
--------------------------------
### Hardhat Ignition Deployment Output
Source: https://hardhat.org/ignition/docs
Example output showing the successful deployment of the 'Apollo' module, including contract execution and final deployment addresses.
```text
Hardhat Ignition 🚀
Deploying [ Apollo ]
Batch #1
Executed Apollo#Rocket
Batch #2
Executed Apollo#Rocket.launch
[ Apollo ] successfully deployed 🚀
Deployed Addresses
Apollo#Rocket - 0x5fbdb2315678afecb367f032d93f642f64180aa3
```
--------------------------------
### Parameter File Example (BigInt)
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Define BigInt parameters by encoding them as strings with an 'n' suffix. This is useful for large numbers like token endowments.
```json
{
"MyModule": {
"endowment": "1000000000000000000n" // 1 ETH in wei
}
}
```
--------------------------------
### Clearing and restarting a deployment with --reset
Source: https://hardhat.org/ignition/docs/guides/modifications.md
Command to clear a previous deployment and start from scratch using the --reset option. This is useful for starting over or when incompatible modifications are made.
```bash
hardhat ignition deploy ignition/modules/Apollo.ts --network localhost --reset
```
--------------------------------
### Install Hardhat Ignition Ethers Plugin
Source: https://hardhat.org/ignition/docs/guides/ethers.md
Installs the necessary package for Ethers support in Hardhat Ignition. Run this command in your project's root directory.
```bash
pnpm install --save-dev @nomicfoundation/hardhat-ignition-ethers
```
--------------------------------
### Example Deployed Addresses JSON Structure
Source: https://hardhat.org/ignition/docs/explanations/deployment-artifacts.md
Illustrates the structure of the `deployed_addresses.json` file, mapping contract future IDs to their deployed addresses.
```json
{
//...
"Mod#foo": "0x..."
//...
}
```
--------------------------------
### Install Hardhat Ignition with npm
Source: https://hardhat.org/ignition/docs
Use npm to add the Hardhat Ignition Viem plugin to your project dependencies.
```bash
npm add --save-dev @nomicfoundation/hardhat-ignition-viem
```
--------------------------------
### Install Hardhat Ignition with pnpm
Source: https://hardhat.org/ignition/docs
Use pnpm to add the Hardhat Ignition Viem plugin to your project dependencies.
```bash
pnpm add --save-dev @nomicfoundation/hardhat-ignition-viem
```
--------------------------------
### Install Hardhat Ignition
Source: https://hardhat.org/ignition/docs/getting-started.md
Install the Hardhat Ignition Viem package using npm, pnpm, or yarn. This command should be run in the root directory of your Hardhat project.
```bash
npm install --save-dev @nomicfoundation/hardhat-ignition-viem
```
--------------------------------
### Install Hardhat Ignition with yarn
Source: https://hardhat.org/ignition/docs
Use yarn to add the Hardhat Ignition Viem plugin to your project dependencies.
```bash
yarn add --dev @nomicfoundation/hardhat-ignition-viem
```
--------------------------------
### List All Deployment IDs
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Run this command to get a list of all deployment IDs currently in your project. This is useful for managing and tracking your deployments.
```bash
npx hardhat ignition deployments
```
--------------------------------
### Use Ignition Modules as fixtures with Hardhat Network Helper
Source: https://hardhat.org/ignition/docs/guides/tests.md
Integrate Ignition module deployments into Hardhat Network Helper fixtures for easy test setup. Call 'ignition.deploy' within a fixture function to deploy contracts before tests run.
```javascript
import { network } from "hardhat";
import assert from "node:assert/strict";
import { it } from "node:test";
async function deployCounterModuleFixture() {
const { ignition } = await network.create();
return ignition.deploy(CounterModule);
}
it("should set the start count to 0 by default", async function () {
const { networkHelpers } = await network.create();
const { counter } = await networkHelpers.loadFixture(
deployCounterModuleFixture,
);
assert.equal(await counter.read.count(), 0);
});
```
--------------------------------
### Define Module for Interacting with Upgraded Proxy
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
This module demonstrates interacting with an upgraded proxy. It uses `contractAt` to get an instance of the new contract version through the proxy address.
```javascript
const demoV2Module = buildModule("DemoV2Module", (m) => {
const { proxy } = m.useModule(upgradeModule);
const demo = m.contractAt("DemoV2", proxy);
return { demo };
});
```
--------------------------------
### Create Ignition Module Directory Structure
Source: https://hardhat.org/ignition/docs
Set up the necessary directories for Hardhat Ignition modules.
```bash
mkdir ignition
mkdir ignition/modules
```
--------------------------------
### Visualize Deployment Module
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
Generate an HTML report to visualize a Hardhat Ignition module. The `--no-open` flag prevents the report from automatically opening in the browser. Requires the module path.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition visualize [--no-open] [--] modulePath
OPTIONS:
--no-open Disables opening report in browser (default: false)
POSITIONAL ARGUMENTS:
modulePath The path to the module file to visualize
```
--------------------------------
### Deploy a library
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Deploy a library using `m.library`. This creates a Future representing the library deployment.
```javascript
const myLib = m.library("MyLib");
```
--------------------------------
### Run Ignition Module Deployment
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Use this command to deploy an Ignition Module. Specify the path to your module file.
```bash
hardhat ignition deploy ignition/modules/MyModule.ts
```
--------------------------------
### Deploy a Contract with Constructor Arguments
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `m.contract` to deploy a new contract instance. Provide the contract name and an array of constructor arguments. The `Future` object returned can be used as an argument for other methods.
```javascript
const token = m.contract("Token", ["My Token", "TKN", 18]);
```
```javascript
const foo = m.contract("ReceivesAnAddress", [token]);
```
--------------------------------
### Demo Contract for Upgradeability
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
A basic Solidity contract demonstrating a simple version function. This serves as the initial implementation that will be upgraded.
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
// A contrived example of a contract that can be upgraded
contract Demo {
function version() public pure returns (string memory) {
return "1.0.0";
}
}
```
--------------------------------
### Test Upgradeable Proxy Deployment and Interaction
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Tests the initial deployment of a demo module and verifies its version via the proxy. Ensure the correct version string is returned.
```typescript
import hre from "hardhat";
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import DemoModule from "../ignition/modules/ProxyModule.js";
import UpgradeModule from "../ignition/modules/UpgradeModule.js";
describe("Demo Proxy", async function () {
const { ignition, viem } = await hre.network.create();
describe("Proxy interaction", function () {
it("Should be usable via proxy", async function () {
const [, otherAccount] = await viem.getWalletClients();
const { demo } = await ignition.deploy(DemoModule);
assert.equal(
await demo.read.version({ account: otherAccount.account.address }),
"1.0.0",
);
});
});
describe("Upgrading", function () {
it("Should have upgraded the proxy to DemoV2", async function () {
const [, otherAccount] = await viem.getWalletClients();
const { demo } = await ignition.deploy(UpgradeModule);
assert.equal(
await demo.read.version({ account: otherAccount.account.address }),
"2.0.0",
);
});
it("Should have set the name during upgrade", async function () {
const [, otherAccount] = await viem.getWalletClients();
const { demo } = await ignition.deploy(UpgradeModule);
assert.equal(
await demo.read.name({ account: otherAccount.account.address }),
"Example Name",
);
});
});
});
```
--------------------------------
### Organize deployments using submodules
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `m.useModule` to include other modules as submodules. This helps organize complex deployments and allows reuse of module logic. Dependencies on futures from submodules are automatically managed.
```javascript
const TokenModule = buildModule("TokenModule", (m) => {
const token = m.contract("Token", ["My Token", "TKN2", 18]);
return { token };
});
const TokenOwnerModule = buildModule("TokenOwnerModule", (m) => {
const { token } = m.useModule(TokenModule);
const owner = m.contract("TokenOwner", [token]);
m.call(token, "transferOwnership", [owner]);
return { owner };
});
```
--------------------------------
### Deploy and Verify Contract on Sepolia
Source: https://hardhat.org/ignition/docs/guides/verify.md
Use the Hardhat Ignition CLI to deploy your module to the Sepolia network and automatically verify the contracts.
```bash
hardhat ignition deploy ignition/modules/Apollo.ts --network sepolia --verify
```
--------------------------------
### Visualize Ignition Module
Source: https://hardhat.org/ignition/docs/guides/visualize.md
Use the `hardhat ignition visualize` command to generate an HTML report of your module's deployment process. This command opens the report in your default browser.
```bash
npx hardhat ignition visualize ./ignition/modules/Apollo.ts
```
--------------------------------
### Deploy Module with Custom Parameters
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Deploy an Ignition Module and provide custom parameters using a JSON file. The `--parameters` flag specifies the path to the parameter file.
```bash
hardhat ignition deploy ignition/modules/Apollo.ts --parameters ignition/parameters.json
```
--------------------------------
### Deploy a Module
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
Use this command to deploy a Hardhat Ignition module to a specified network. Options include setting a default sender, specifying a deployment ID, providing parameters via a JSON file, resetting the deployment state, choosing a deployment strategy, and verifying the deployment.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition deploy [--default-sender ] [--deployment-id ] [--parameters ] [--reset] [--strategy ] [--verify] [--write-localhost-deployment] [--] modulePath
OPTIONS:
--default-sender Set the default sender for the deployment
--deployment-id Set the id of the deployment
--parameters A relative path to a JSON file to use for the module parameters
--reset Wipes the existing deployment state before deploying (default: false)
--strategy Set the deployment strategy to use (default: basic)
--verify Verify the deployment on all enabled verifiers (default: false)
--write-localhost-deployment Write deployment information to disk when deploying to the in-memory network (default: false)
POSITIONAL ARGUMENTS:
modulePath The path to the module file to deploy
```
--------------------------------
### Run Hardhat Ignition Deploy Command
Source: https://hardhat.org/ignition/docs/guides/ledger.md
Execute the Hardhat Ignition deploy command specifying your module and network. This command will prompt for keystore password and Ledger confirmation.
```bash
hardhat ignition deploy ignition/modules/Apollo.ts --network sepolia
```
--------------------------------
### Use an Existing Contract Instance
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `m.contractAt` to create a `Future` representing an already deployed contract. Provide the contract name and its address.
```javascript
const existingToken = m.contractAt("Token", "0x...");
```
--------------------------------
### Deploy a Contract Sending ETH to Constructor
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
To send ETH to a contract's constructor, use the `value` field within the options object as the third argument to `m.contract`.
```javascript
const bar = m.contract("ReceivesETH", [], {
value: 1_000_000_000n, // 1gwei
});
```
--------------------------------
### Configure Hardhat for Sepolia Network with Ledger
Source: https://hardhat.org/ignition/docs/guides/ledger.md
Set up your Hardhat configuration to use the Sepolia testnet and the Hardhat Ledger plugin. Ensure your Alchemy URL is stored in the Hardhat keystore and specify your Ledger account address.
```typescript
import {
defineConfig,
configVariable
} from "hardhat/config";
import hardhatLedgerPlugin from "@nomicfoundation/hardhat-ledger";
export default defineConfig({
plugins: [hardhatLedgerPlugin],
networks: {
sepolia: {
type: "http",
// Go to https://alchemy.com, sign up, create a new App in its dashboard,
// and set the ALCHEMY_URL secret in the Hardhat keystore.
// Example: https://eth-sepolia.g.alchemy.com/v2/
url: configVariable("ALCHEMY_URL"),
ledgerAccounts: [
// Set your ledger address here
"0x070Da0697e6B82F0ab3f5D0FD9210EAdF2Ba1516",
],
},
},
});
```
--------------------------------
### Link Library When Deploying Contract
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use the `libraries` field in the options object to link a library when deploying a contract. This is applicable when calling `m.contract` or `m.library`.
```javascript
const myLib = m.library("MyLib");
const myContract = m.contract("MyContract", [], {
libraries: {
MyLib: myLib,
},
});
```
--------------------------------
### Deploy Ignition Module with Create2 Strategy
Source: https://hardhat.org/ignition/docs/guides/create2.md
Execute an Ignition module deployment using the create2 strategy on the Sepolia network. This command ensures the module is deployed to a predictable address.
```bash
hardhat ignition deploy ignition/modules/Apollo.ts --network sepolia --strategy create2
```
--------------------------------
### Show Deployment Transactions
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
This command lists all transactions associated with a given deployment ID.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition transactions [--] deploymentId
POSITIONAL ARGUMENTS:
deploymentId The id of the deployment to show transactions for
```
--------------------------------
### Deploy Ignition Module to Localhost
Source: https://hardhat.org/ignition/docs
Deploys the 'Apollo' Ignition module to the local Hardhat network. Ensure a local node is running before executing this command.
```bash
npx hardhat ignition deploy ignition/modules/Apollo.ts --network localhost
```
```bash
pnpm hardhat ignition deploy ignition/modules/Apollo.ts --network localhost
```
```bash
yarn hardhat ignition deploy ignition/modules/Apollo.ts --network localhost
```
--------------------------------
### Deploy TransparentUpgradeableProxy Module
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Defines a Hardhat Ignition module to deploy a Demo contract and its TransparentUpgradeableProxy. It retrieves the ProxyAdmin address from an event and attaches the ABI for interaction.
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
const proxyModule = buildModule("ProxyModule", (m) => {
const proxyAdminOwner = m.getAccount(0);
const demo = m.contract("Demo");
const proxy = m.contract("TransparentUpgradeableProxy", [
demo,
proxyAdminOwner,
"0x",
]);
const proxyAdminAddress = m.readEventArgument(
proxy,
"AdminChanged",
"newAdmin",
);
const proxyAdmin = m.contractAt("ProxyAdmin", proxyAdminAddress);
return { proxyAdmin, proxy };
});
```
--------------------------------
### Configure Hardhat for Sepolia Network
Source: https://hardhat.org/ignition/docs/guides/verify.md
Set up your Hardhat configuration to connect to the Sepolia testnet using an RPC URL and private key.
```typescript
// hardhat.config.ts
import { configVariable, defineConfig } from "hardhat/config";
// Go to https://alchemy.com, sign up, create a new App in
// its dashboard, and set the Hardhat configuration variable
// ALCHEMY_RPC_URL to the key
const ALCHEMY_RPC_URL = configVariable("ALCHEMY_RPC_URL");
// Replace this private key with your Sepolia test account private key
// To export your private key from Coinbase Wallet, go to
// Settings > Developer Settings > Show private key
// To export your private key from Metamask, open Metamask and
// go to Account Details > Export Private Key
// Beware: NEVER put real Ether into testing accounts
const SEPOLIA_PRIVATE_KEY = configVariable("SEPOLIA_PRIVATE_KEY");
export default defineConfig({
// ...rest of your config...
networks: {
sepolia: {
url: ALCHEMY_RPC_URL,
accounts: [SEPOLIA_PRIVATE_KEY],
},
},
});
```
--------------------------------
### List All Deployments
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
This command lists all deployment IDs managed by Hardhat Ignition.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition deployments
```
--------------------------------
### Deploy a module and assert contract state
Source: https://hardhat.org/ignition/docs/guides/tests.md
Deploy an Ignition module and interact with the deployed contracts. The 'ignition.deploy' method returns an object with Viem contracts for each contract Future.
```javascript
import { network } from "hardhat";
import assert from "node:assert/strict";
import { it } from "node:test";
const CounterModule = buildModule("Counter", (m) => {
const startCount = m.getParameter("startCount", 0);
const counter = m.contract("Counter", [startCount]);
return { counter };
});
it("should set the start count to 0 by default", async function () {
const { ignition } = await network.create();
const { counter } = await ignition.deploy(CounterModule);
assert.equal(await counter.read.count(), 0);
});
```
--------------------------------
### Verify Deployment Contracts
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
Verify smart contracts from a deployment against configured block explorers. The `--force` option can be used to re-verify contracts. Requires the deployment ID.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition verify [--force] [--] deploymentId
OPTIONS:
--force Force verification (default: false)
POSITIONAL ARGUMENTS:
deploymentId The id of the deployment to verify
```
--------------------------------
### Define Upgrade Module
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Use this module to deploy a new contract version and upgrade an existing proxy to it. It encodes a function call to initialize the new implementation.
```javascript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import DemoModule from "./ProxyModule.js";
const upgradeModule = buildModule("UpgradeModule", (m) => {
const proxyAdminOwner = m.getAccount(0);
const { proxyAdmin, proxy } = m.useModule(DemoModule);
const demoV2 = m.contract("DemoV2");
const encodedFunctionCall = m.encodeFunctionCall(demoV2, "setName", [
"Example Name",
]);
m.call(proxyAdmin, "upgradeAndCall", [proxy, demoV2, encodedFunctionCall], {
from: proxyAdminOwner,
});
return { proxyAdmin, proxy };
});
```
--------------------------------
### Handle Asynchronous Operations in Hardhat Script for Deployment
Source: https://hardhat.org/ignition/docs/guides/scripts.md
This script demonstrates how to perform asynchronous operations, like fetching data from an API, before deploying an Ignition module with dynamic parameters.
```typescript
import hre from "hardhat";
import ApolloModule from "../ignition/modules/Apollo.js";
async function getRocketNameFromAPI() {
// Mock function to simulate an asynchronous API call
return "Saturn VI";
}
async function main() {
const rocketName = await getRocketNameFromAPI();
const connection = await hre.network.create();
const { apollo } = await connection.ignition.deploy(ApolloModule, {
parameters: { Apollo: { rocketName } },
});
console.log(`Apollo deployed to: ${apollo.address}`);
}
main().catch(console.error);
```
--------------------------------
### Verify Existing Deployment on Sepolia
Source: https://hardhat.org/ignition/docs/guides/verify.md
Run the Hardhat Ignition verify task directly, providing the deployment ID to verify previously deployed contracts.
```bash
hardhat ignition verify chain-11155111
```
--------------------------------
### Configure Sepolia Network in Hardhat
Source: https://hardhat.org/ignition/docs/guides/create2.md
Add the Sepolia network configuration to your Hardhat config file, including RPC URL and private key for account access. Ensure environment variables for ALCHEMY_RPC_URL and SEPOLIA_PRIVATE_KEY are set.
```typescript
import { configVariable, defineConfig } from "hardhat/config";
// Go to https://alchemy.com, sign up, create a new App in
// its dashboard, and set the Hardhat configuration variable
// ALCHEMY_RPC_URL to the full RPC URL, including the API key
const ALCHEMY_RPC_URL = configVariable("ALCHEMY_RPC_URL");
// Replace this private key with your Sepolia test account private key
// To export your private key from Coinbase Wallet, go to
// Settings > Developer Settings > Show private key
// To export your private key from Metamask, open Metamask and
// go to Account Details > Export Private Key
// Beware: NEVER put real Ether into testing accounts
const SEPOLIA_PRIVATE_KEY = configVariable("SEPOLIA_PRIVATE_KEY");
export default defineConfig({
// ...rest of your config...
networks: {
sepolia: {
url: ALCHEMY_RPC_URL,
accounts: [SEPOLIA_PRIVATE_KEY],
},
},
});
```
--------------------------------
### Interact with Demo Contract via Proxy Module
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Defines a Hardhat Ignition module to interact with a deployed Demo contract through its proxy. It uses `m.useModule` to import the proxy and `m.contractAt` to attach the Demo ABI to the proxy address.
```javascript
const demoModule = buildModule("DemoModule", (m) => {
const { proxy, proxyAdmin } = m.useModule(proxyModule);
const demo = m.contractAt("Demo", proxy);
return { demo, proxy, proxyAdmin };
});
```
--------------------------------
### Log Deployed Contract Address with Hardhat Script
Source: https://hardhat.org/ignition/docs/guides/scripts.md
Use this script to deploy an Ignition module and log the address of the deployed contract. Requires the Apollo module and Viem for contract instance.
```typescript
import hre from "hardhat";
import ApolloModule from "../ignition/modules/Apollo.js";
async function main() {
const connection = await hre.network.create();
const { apollo } = await connection.ignition.deploy(ApolloModule);
// or `apollo.getAddress()` if you're using Ethers.js
console.log(`Apollo deployed to: ${apollo.address}`);
}
main().catch(console.error);
```
--------------------------------
### Configure Hardhat for OpenZeppelin Proxy Contracts
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Configures Hardhat to compile OpenZeppelin Contracts, specifically the proxy administration and upgradeable proxy contracts. This is required for using them in Ignition modules.
```typescript
// hardhat.config.ts
import { defineConfig } from "hardhat/config";
export default defineConfig({
solidity: {
npmFilesToBuild: [
"@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol",
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol",
],
},
});
```
--------------------------------
### Enable Hardhat Ignition Plugin in Hardhat Config
Source: https://hardhat.org/ignition/docs
Configure your Hardhat project to use the Hardhat Ignition Viem plugin by adding it to the plugins array in your hardhat.config.js or hardhat.config.ts file.
```typescript
import { defineConfig } from "hardhat/config";
import hardhatIgnitionViemPlugin from "@nomicfoundation/hardhat-ignition-viem";
export default defineConfig({
plugins: [hardhatIgnitionViemPlugin],
// ... rest of your config
});
```
--------------------------------
### Set module parameters during deployment
Source: https://hardhat.org/ignition/docs/guides/tests.md
Provide module parameters to 'ignition.deploy' via the 'parameters' field in the options object. This allows customization of deployed contracts, such as setting an initial value.
```javascript
import { network } from "hardhat";
import assert from "node:assert/strict";
import { it } from "node:test";
it("should allow setting the start count for new counters", async function () {
const { ignition } = await network.create();
const { counter } = await ignition.deploy(CounterModule, {
parameters: {
Counter: {
startCount: 42,
},
},
});
assert.equal(await counter.read.count(), 42);
});
```
--------------------------------
### Deploy contracts from a specific account
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Specify the sender account for contract deployments or calls using the `from` option. You can use a hardcoded address or retrieve an account managed by Hardhat.
```javascript
const token = m.contract("Token", ["My Token", "TKN2", 18], { from: "0x...." });
```
```javascript
const account1 = m.getAccount(1);
const token = m.contract("Token", ["My Token", "TKN2", 18], { from: account1 });
```
--------------------------------
### Configure Hardhat Ignition Plugin
Source: https://hardhat.org/ignition/docs/getting-started.md
Add the Hardhat Ignition Viem plugin to your hardhat.config.ts file to enable its functionality. Ensure Hardhat version 3.0.0 or higher is used.
```typescript
import { defineConfig } from "hardhat/config";
import hardhatIgnitionViemPlugin from "@nomicfoundation/hardhat-ignition-viem";
export default defineConfig({
plugins: [hardhatIgnitionViemPlugin],
// ... rest of your config
});
```
--------------------------------
### Migrate Deployment Artifacts
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
Use this command to migrate deployment artifacts to the new Hardhat 3 format. Requires the deployment ID of the artifacts to migrate.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition migrate [--] deploymentId
POSITIONAL ARGUMENTS:
deploymentId The id of the deployment to migrate
```
--------------------------------
### Send ETH to an account
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `m.send` to transfer ETH to a specified address. The third parameter defines the amount of ETH to send.
```javascript
const send = m.send("SendingEth", address, 1_000_000_000n);
```
--------------------------------
### Configure Network-Specific Hardhat Ignition Settings
Source: https://hardhat.org/ignition/docs/reference/config.md
Customize Hardhat Ignition deployments on a per-network basis by configuring the `ignition` field within a specific network's configuration in `hardhat.config.ts`. This allows for tailored gas fee limits and other network-specific behaviors.
```typescript
import { defineConfig } from "hardhat/config";
export default defineConfig({
networks: {
sepolia: {
// ...
ignition: {
maxFeePerGasLimit: 50_000_000_000n, // 50 gwei
maxFeePerGas: 20_000_000_000n, // 20 gwei
maxPriorityFeePerGas: 2_000_000_000n, // 2 gwei
gasPrice: 50_000_000_000n, // 50 gwei
disableFeeBumping: false,
explorerUrl: "https://sepolia.etherscan.io",
maxRetries: 10,
retryInterval: 1_000,
},
// ...
},
},
});
```
--------------------------------
### Define a Basic Ignition Module
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `buildModule` to create a module with a unique ID and define its contents via a callback function. The `m` parameter is a `ModuleBuilder` used to define contract futures.
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("MyToken", (m) => {
const token = m.contract("Token", ["My Token", "TKN", 18]);
return { token };
});
```
--------------------------------
### Show Deployment Status
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
This command displays the current status of a specified deployment. It requires the deployment ID as an argument.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition status [--] deploymentId
POSITIONAL ARGUMENTS:
deploymentId The id of the deployment to show
```
--------------------------------
### Configure Global Hardhat Ignition Settings
Source: https://hardhat.org/ignition/docs/reference/config.md
Customize global Hardhat Ignition behavior by setting options in the `ignition` field of your `hardhat.config.ts`. This includes parameters for transaction fee bumping and retries.
```typescript
import { defineConfig } from "hardhat/config";
export default defineConfig({
ignition: {
blockPollingInterval: 1_000,
timeBeforeBumpingFees: 3 * 60 * 1_000,
maxFeeBumps: 4,
requiredConfirmations: 5,
disableFeeBumping: false,
maxRetries: 10,
retryInterval: 1_000,
},
});
```
--------------------------------
### Use existing contract artifacts
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Deploy or interact with contracts not part of your Hardhat project by providing their artifacts directly. The contract name is used for `Future` IDs.
```javascript
const token = m.contract("Token", TokenArtifact, ["My Token", "TKN2", 18]);
const myLib = m.library("MyLib", MyLibArtifact);
const token2 = m.contractAt("Token", TokenArtifact, token2Address);
```
--------------------------------
### Deploy Ignition Module via Hardhat Script
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Deploy an Ignition Module programmatically within a Hardhat script. Pass parameters using an absolute path to the JSON file.
```typescript
import hre from "hardhat";
import path from "path";
import ApolloModule from "../ignition/modules/Apollo.js";
async function main() {
const connection = await hre.network.create();
const { apollo } = await connection.ignition.deploy(ApolloModule, {
// This must be an absolute path to your parameters JSON file
parameters: path.resolve(
import.meta.dirname,
"../ignition/parameters.json",
),
});
// or `apollo.getAddress()` if you're using Ethers.js
console.log(`Apollo deployed to: ${apollo.address}`);
}
main().catch(console.error);
```
--------------------------------
### Define a Simple Rocket Contract
Source: https://hardhat.org/ignition/docs
This Solidity contract defines a basic 'Rocket' with a name and status, and a 'launch' function to change its status. It's used for demonstrating Hardhat Ignition deployment.
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract Rocket {
string public name;
string public status;
constructor(string memory _name) {
name = _name;
status = "ignition";
}
function launch() public {
status = "lift-off";
}
}
```
--------------------------------
### Configure Create2 Salt in Hardhat Ignition
Source: https://hardhat.org/ignition/docs/guides/create2.md
Set the salt for create2 deployments within the Hardhat Ignition configuration. This salt is crucial for deterministic address generation and must be a 32-byte hex-encoded string.
```typescript
import { defineConfig } from "hardhat/config";
export default defineConfig({
// ...rest of your config...
ignition: {
strategyConfig: {
create2: {
// To learn more about salts, see the CreateX documentation
salt: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
},
},
});
```
--------------------------------
### Define a module with configurable parameters
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Make contract constructor arguments configurable using `m.getParameter`. Provide a default value as the second argument to `m.getParameter` to make the parameter optional.
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("Apollo", (m) => {
const apollo = m.contract("Rocket", [m.getParameter("name", "Saturn V")]);
m.call(apollo, "launch", []);
return { apollo };
});
```
--------------------------------
### Configure Etherscan API Key
Source: https://hardhat.org/ignition/docs/guides/verify.md
Add your Etherscan API key as a configuration variable in your Hardhat config file. This is required for verifying contracts on Etherscan.
```typescript
import { configVariable, defineConfig } from "hardhat/config";
export default defineConfig({
// ...rest of the config...
verify: {
etherscan: {
apiKey: configVariable("ETHERSCAN_API_KEY"),
},
},
});
```
--------------------------------
### Define a Simple Rocket Contract
Source: https://hardhat.org/ignition/docs/getting-started.md
A basic Solidity contract named Rocket with a constructor that sets a name and an initialization function 'launch' to change its status. This contract is used to demonstrate Hardhat Ignition's deployment capabilities.
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract Rocket {
string public name;
string public status;
constructor(string memory _name) {
name = _name;
status = "ignition";
}
function launch() public {
status = "lift-off";
}
}
```
--------------------------------
### Send data to an account
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `m.send` to send arbitrary data to an address. The fourth parameter specifies the data payload.
```javascript
const send = m.send("SendingData", address, undefined, "0x16417104");
```
--------------------------------
### Export Demo Module
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Exports the DemoModule for deployment and usage in Hardhat scripts or tests.
```typescript
export default demoModule;
```
--------------------------------
### Check Deployment Status
Source: https://hardhat.org/ignition/docs/guides/deploy.md
Use this command to check the current status of a specific deployment by providing its ID. It helps in verifying if a deployment was successful.
```bash
npx hardhat ignition status DeploymentId
```
--------------------------------
### Deploy Ignition Module with Ethers Contract Instance
Source: https://hardhat.org/ignition/docs/guides/ethers.md
Deploys an Ignition module and retrieves the deployed contract as an Ethers.js contract instance. This is useful for interacting with the deployed contract within tests or scripts.
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import hre from "hardhat";
const ApolloModule = buildModule("Apollo", (m) => {
const apollo = m.contract("Rocket", ["Saturn V"]);
return { apollo };
});
it("should have named the rocket Saturn V", async function () {
const connection = await hre.network.create();
const { apollo } = await connection.ignition.deploy(ApolloModule);
assert.equal(await apollo.getFunction("name")(), "Saturn V");
});
```
--------------------------------
### Set explicit dependencies between Futures
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use the `after` field in the options object to set explicit dependencies between `Future` objects. This ensures that one `Future` is deployed only after another has completed.
```javascript
const token = m.contract("Token", ["My Token", "TKN", 18]);
const receiver = m.contract("Receiver", [], {
after: [token], // `receiver` is deployed after `token`
});
```
--------------------------------
### Add new contract instance and calls to a module
Source: https://hardhat.org/ignition/docs/guides/modifications.md
Modify an existing module to include a new contract instance and its associated calls. Hardhat Ignition will detect and execute only the new parts.
```typescript
import {
buildModule
} from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("Apollo", (m) => {
const apollo = m.contract("Rocket", ["Saturn V"]);
m.call(apollo, "launch", []);
const artemis = m.contract("Rocket", ["Artemis 2"], { id: "artemis" });
m.call(artemis, "launch", []);
return { apollo, artemis };
});
```
--------------------------------
### Track Missing Transaction
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
Use this command to track a transaction that is missing from a deployment. This should only be used if an error message suggests it. Requires the transaction hash and the deployment ID.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition track-tx [--] txHash deploymentId
POSITIONAL ARGUMENTS:
deploymentId The id of the deployment to add the tx to
txHash The hash of the transaction to track
```
--------------------------------
### DemoV2 Contract for Upgradeability
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
An upgraded version of the Demo contract. It includes a new state variable `name` and a `setName` function, in addition to the original `version` function.
```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
// A contrived example of a contract that can be upgraded
contract DemoV2 {
string public name;
function version() public pure returns (string memory) {
return "2.0.0";
}
function setName(string memory _name) public {
name = _name;
}
}
```
--------------------------------
### Deploying a modified module
Source: https://hardhat.org/ignition/docs/guides/modifications.md
Command to deploy a modified Ignition module. Hardhat Ignition will continue from where it left off, executing only the new parts of the module.
```bash
hardhat ignition deploy ignition/modules/Apollo.ts --network localhost
```
--------------------------------
### Export Module
Source: https://hardhat.org/ignition/docs/guides/upgradeable-proxies.md
Export the module definition to make it available for deployment via tests or scripts.
```typescript
export default demoV2Module;
```
--------------------------------
### Enable Hardhat Ignition Ethers Plugin
Source: https://hardhat.org/ignition/docs/guides/ethers.md
Enables the Hardhat Ignition Ethers plugin by adding it to the plugins array in your hardhat.config.ts file. Ensure only one Hardhat Ignition package is imported.
```typescript
import { defineConfig } from "hardhat/config";
import HardhatIgnitionEthersPlugin from "@nomicfoundation/hardhat-ignition-ethers";
export default defineConfig({
plugins: [HardhatIgnitionEthersPlugin],
// ... rest of your config
});
```
--------------------------------
### Create Ignition Module for Apollo Contract
Source: https://hardhat.org/ignition/docs/getting-started.md
Define a Hardhat Ignition module to deploy a 'Rocket' contract and call its 'launch' function. This module is identified as 'Apollo' and returns the deployed 'Rocket' contract instance.
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("Apollo", (m) => {
const apollo = m.contract("Rocket", ["Saturn V"]);
m.call(apollo, "launch", []);
return { apollo };
});
```
--------------------------------
### Deploy Module Conditionally with Hardhat Script
Source: https://hardhat.org/ignition/docs/guides/scripts.md
Use an if statement within a Hardhat script to conditionally deploy an Ignition module based on external conditions, such as data fetched from an API. This allows for dynamic deployment logic.
```typescript
import ApolloModule from "../ignition/modules/Apollo.js";
async function getRocketNameFromAPI() {
// Mock function to simulate an asynchronous API call
return "Saturn VI";
}
async function main() {
const rocketName = await getRocketNameFromAPI();
if (rocketName !== undefined) {
const { apollo } = await hre.ignition.deploy(ApolloModule, {
parameters: { Apollo: { rocketName } },
});
console.log(`Apollo deployed to: ${apollo.address}`);
} else {
console.log("No name given for Rocket contract, skipping deployment");
}
}
main().catch(console.error);
```
--------------------------------
### Define a Hardhat Ignition Module (Apollo.ts)
Source: https://hardhat.org/ignition/docs
Defines a module named 'Apollo' that deploys a 'Rocket' contract and calls its 'launch' function. This module uses the `buildModule` function and `ModuleBuilder` to define contract deployment and interaction futures.
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
export default buildModule("Apollo", (m) => {
const apollo = m.contract("Rocket", ["Saturn V"]);
m.call(apollo, "launch", []);
return { apollo };
});
```
--------------------------------
### Call a contract function with ETH value
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Send ETH when calling a contract function by providing a `value` in the options object passed as the fourth argument to `m.call`.
```javascript
m.call(myContract, "receivesEth", [], {
value: 1_000_000_000n, // 1gwei
});
```
--------------------------------
### Call a contract function
Source: https://hardhat.org/ignition/docs/guides/creating-modules.md
Use `m.call` to invoke a contract function. Pass the contract's Future, function name, and arguments. Ignition resolves nested Futures automatically.
```javascript
m.call(token, "transfer", [receiver, amount]);
```
--------------------------------
### Deploy Ignition Module with a Specific Sender Account
Source: https://hardhat.org/ignition/docs/guides/ethers.md
Deploys an Ignition module using a specified sender account. This allows you to control which account initiates the deployment transactions.
```typescript
const connection = await hre.network.create();
const [first, second] = await connection.ethers.getSigners();
const result = await connection.ignition.deploy(ApolloModule, {
defaultSender: second.address,
});
```
--------------------------------
### Add Unique Identifier to Contract
Source: https://hardhat.org/ignition/docs/guides/verify.md
Modify your contract's source code by adding a unique comment to ensure it can be verified on Sepolia.
```solidity
// Author: @john
contract Rocket {
```
--------------------------------
### Wipe Deployment Future
Source: https://hardhat.org/ignition/docs/reference/cli-commands.md
Reset a specific future within a deployment to allow for rerunning. Requires both the deployment ID and the future ID.
```bash
Usage: hardhat [GLOBAL OPTIONS] ignition wipe [--] deploymentId futureId
POSITIONAL ARGUMENTS:
deploymentId The id of the deployment with the future to wipe
futureId The id of the future to wipe
```
--------------------------------
### Specify a default sender for transactions
Source: https://hardhat.org/ignition/docs/guides/tests.md
Change the default sender account for Ignition deployment transactions by providing the 'defaultSender' option to the 'ignition.deploy' method.
```typescript
const connection = await network.create();
const [first, second] = await connection.viem.getWalletClients();
const result = await connection.ignition.deploy(CounterModule, {
defaultSender: second.account.address,
});
```