Why testnet first?
Testnets let you deploy and interact with contracts in a real EVM environment without using real ETH. Sepolia is the primary Ethereum testnet as of 2024 — it has a faucet, full tooling support, and mirrors mainnet behavior closely.
Configure Hardhat for Sepolia
// hardhat.config.js
require('@nomicfoundation/hardhat-toolbox');
require('dotenv').config();
module.exports = {
solidity: '0.8.20',
networks: {
sepolia: {
url: process.env.SEPOLIA_RPC_URL, // Alchemy or Infura RPC URL
accounts: [process.env.DEPLOYER_PRIVATE_KEY]
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY
}
};# .env
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
DEPLOYER_PRIVATE_KEY=0x...
ETHERSCAN_API_KEY=YOUR_KEYNever commit your .env file. Add it to .gitignore immediately.
Get Sepolia ETH
Use a faucet to get test ETH:
- Alchemy Sepolia Faucet
- Chainlink Faucet
- Infura Sepolia Faucet
Write an Ignition deployment module
// ignition/modules/MyToken.js
const { buildModule } = require('@nomicfoundation/hardhat-ignition/modules');
module.exports = buildModule('MyTokenModule', (m) => {
const myToken = m.contract('MyToken');
return { myToken };
});Deploy
npx hardhat ignition deploy ignition/modules/MyToken.js --network sepoliaHardhat will output the deployed contract address. Save it — you'll need it to verify and interact with the contract.
Confirm on Etherscan
Paste your contract address into sepolia.etherscan.io to see the deployment transaction, bytecode, and any interactions.
Test thoroughly on testnet before mainnet
Run every function you intend to expose. Test edge cases. Test with multiple accounts. Test failure conditions. The cost of a bug on mainnet is real money and reputational damage — the cost on testnet is nothing.