Solidity theorytheory 0/50 · 0%
Tooling · hard

40. Testing and deploying with Hardhat

JavaScript tests, scripts and verification.

Hardhat pairs a JS/TS test suite with ethers. Deployment scripts fetch a factory, deploy, wait for confirmations, then verify the source on the block explorer.

const f = await ethers.getContractFactory("SimpleStaking");
const c = await f.deploy(rewardRate);
await c.waitForDeployment();
console.log(await c.getAddress());

Keep private keys in environment variables, never in the repo, and always deploy to a testnet such as Base Sepolia first.

Check your understanding

  1. 1. What does `getContractFactory` return?

  2. 2. Where should a deploy key live?

  3. 3. Why verify the contract on the explorer?