In Hardhat 6, deployment is done using the Ignition
module, which introduces a declarative way to manage deployments. The process is different from the Hardhat 5 approach. With Ignition
, you define your deployment logic using modules, which then handle the deployment of contracts. To specify which wallet to use for the deployment of your smart contract, you can follow the below steps.
Ignition Deployment in Hardhat 6
With Hardhat 6 and Ignition
, the deployment process uses the deployer
specified in the ignition module, or it defaults to the first account provided by the Hardhat network if no deployer is explicitly set.
Example: Deploying Contracts Using an Ignition Module
import { buildModule, Account } from "@nomicfoundation/hardhat-ignition";
export const myModule = buildModule("MyModule", (m) => {
const deployer: Account = m.getAccount(0); // Use the first account by default
const myContract = m.contract("MyContract", {
from: deployer,
args: [/* constructor arguments here */],
});
return { myContract };
});
In this code:
m.getAccount(0)
: Retrieves the first account provided by Hardhat as the deployer. This account will be the owner of the deployed contract ifOwnable
or similar logic is used.from: deployer
: Specifies that the contract should be deployed from thedeployer
account.
Steps to Deploy Using the Ignition Module
-
Create an Ignition Module: Define a module that specifies how your contracts should be deployed.
- Configure Deployment Accounts:
- By default, the first account (
m.getAccount(0)
) is used. - You can specify a different account by using
m.getAccount(1)
,m.getAccount(2)
, etc.
- By default, the first account (
-
Run the Deployment: You deploy the module using Hardhat’s Ignition system:
npx hardhat ignition deploy ./ignition/modules/MyContract.ts
Note: You can specify the
--network node
in the above command if you want your changes to persist.
Setting a Custom Deployer Account
To change the deployer, simply select a different account in your module:
import { buildModule, Account } from "@nomicfoundation/hardhat-ignition";
export const myModule = buildModule("MyModule", (m) => {
const deployer: Account = m.getAccount(1); // Use the second account as deployer
const myContract = m.contract("MyContract", {
from: deployer,
args: [/* constructor arguments here */],
});
return { myContract };
});
Summary
In Hardhat 6 with Ignition
, the account used to deploy contracts is determined by the account specified in the ignition module. If no specific account is chosen, the default is the first account (m.getAccount(0)
). The owner of the deployed contract is typically this deployer account unless overridden in the contract’s constructor logic.
This method allows more structured and controlled deployments, integrating well with the modern practices encouraged by Hardhat 6.