#Deploying your contracts
To deploy your contracts, you can use Hardhat Ignition, our declarative deployment system. You can deploy the Lock
contract from the sample project by specifying a deployment with an Ignition Module file like this:
TypeScript
JavaScript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
const ONE_GWEI: bigint = 1_000_000_000n;
const LockModule = buildModule("LockModule", (m) => {
const unlockTime = m.getParameter("unlockTime");
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
const lock = m.contract("Lock", [unlockTime], {
value: lockedAmount,
});
return { lock };
});
export default LockModule;
const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
const ONE_GWEI = 1_000_000_000n;
module.exports = buildModule("LockModule", (m) => {
const unlockTime = m.getParameter("unlockTime");
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
const lock = m.contract("Lock", [unlockTime], {
value: lockedAmount,
});
return { lock };
});
You can deploy in the localhost
network following these steps:
-
Start a local node
npx hardhat node
-
Open a new terminal and deploy the Hardhat Ignition module in the
localhost
networkTypeScriptJavaScriptnpx hardhat ignition deploy ./ignition/modules/LockModule.ts --network localhost
npx hardhat ignition deploy ./ignition/modules/LockModule.js --network localhost
As general rule, you can target any network from your Hardhat config using:
npx hardhat ignition deploy ./ignition/modules/LockModule.js --network <your-network>
If no network is specified, Hardhat Ignition will run against an in-memory instance of Hardhat Network.
Read more about Hardhat Ignition in the Hardhat Ignition documentation.