Lesson 25 of 25
Deploying to Mainnet
Testnets, Etherscan verification, deployment scripts, and going live safely.
AdvancedPre-Deployment Checklist
Before deploying to mainnet with real money at stake:
- ✅ All tests pass (unit + integration)
- ✅ Security audit completed (or at minimum a self-audit)
- ✅ Tested on Sepolia/Goerli testnet
- ✅ Gas costs benchmarked and optimized
- ✅ Contract verified on Etherscan
- ✅ Emergency pause mechanism in place
- ✅ Upgrade path defined (if needed)
- ✅ Multi-sig owner (not single EOA)
Hardhat Deployment Script
Use Hardhat Ignition (or scripts) for reproducible, trackable deployments.
Solidity
// scripts/deploy.js
const { ethers } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying with:", deployer.address);
console.log("Balance:", ethers.formatEther(
await ethers.provider.getBalance(deployer.address)), "ETH");
const MyContract = await ethers.getContractFactory("MyContract");
// Deploy with constructor args
const contract = await MyContract.deploy("arg1", 42, {
gasLimit: 500_000, // explicit gas limit
});
await contract.waitForDeployment();
const addr = await contract.getAddress();
console.log("Deployed to:", addr);
// Verify on Etherscan
if (network.name !== "hardhat") {
console.log("Waiting for confirmations...");
await contract.deploymentTransaction().wait(5);
await run("verify:verify", {
address: addr,
constructorArguments: ["arg1", 42],
});
}
}
main().catch(console.error);
Hardhat Config for Mainnet
Configure networks, gas settings, and API keys in
hardhat.config.js.
Solidity
// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: {
version: "0.8.24",
settings: {
optimizer: { enabled: true, runs: 200 },
viaIR: true, // enables more aggressive optimization
}
},
networks: {
sepolia: {
url: process.env.SEPOLIA_RPC_URL,
accounts: [process.env.PRIVATE_KEY],
gasPrice: "auto",
},
mainnet: {
url: process.env.MAINNET_RPC_URL,
accounts: [process.env.PRIVATE_KEY],
gasPrice: "auto",
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
gasReporter: {
enabled: true,
currency: "USD",
coinmarketcap: process.env.CMC_API_KEY,
}
};
Congratulations!
🎉 You've completed all 25 lessons of SolidityMaster! You now have the knowledge to build, secure, and deploy production-grade smart contracts on Ethereum.
Your next steps:
- Build a full project: DEX, NFT marketplace, or DAO
- Study real audit reports on Code4rena
- Contribute to open source: OpenZeppelin, Uniswap, Aave
- Practice CTF challenges on Ethernaut
- Read the official Solidity documentation
🚀 Ready to build a real blockchain project?
Try this hands-on tutorial: Create a Cryptocurrency Using Truffle (MetaCoin Project)
Try this hands-on tutorial: Create a Cryptocurrency Using Truffle (MetaCoin Project)