Verification and Production Deployment
A deployment is not finished when the transaction is mined. This lesson explains source verification on block explorers, protecting keys and secrets, and the checklist teams follow before and after a mainnet deployment.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how source verification works.
- Compare Etherscan, Sourcify and Blockscout verification.
- Identify practices that protect deployment keys.
- Describe a production deployment checklist.
Source verification
Users interacting with a contract see only bytecode unless its source is verified. Verification submits the source files, compiler version, settings and constructor arguments to a service that recompiles them and checks that the output matches the deployed bytecode. The following comparison shows the main services.
npx hardhat verify --network sepolia 0xYourContract "0xOwnerAddress"
npx hardhat ignition deploy ignition/modules/ClubModule.js --network sepolia --verifynpx hardhat verify submits to every configured explorer; the Ignition --verify flag verifies as part of deployment. Remix offers a contract verification plugin. Verification fails if the compiler version, optimizer settings, EVM version or constructor arguments differ from those used at deployment.
Why verification fails
Protecting keys and secrets
The following practices keep deployment secrets safe.
- Never write private keys, mnemonics or RPC API keys into configuration files or commit them to source control, even for testnets.
- Use
configVariablewith the Hardhat keystore (encrypted) or environment variables; older projects used.envfiles, which must be in.gitignore. - Use a dedicated deployer account holding only the ether needed for the deployment.
- Sign mainnet deployments with a hardware wallet where possible.
- Rotate any key that has appeared in a repository, log or screenshot; treat it as compromised.
Leaked keys are drained in seconds
Bots scan public repositories continuously for private keys and drain funded accounts within seconds of a push. Deleting the commit afterwards does not help, because the key has already been copied.
Safe with secrets?
A production deployment checklist
Teams typically follow a sequence like the following for a mainnet launch.
-
Freeze and review
Freeze the code, complete tests, static analysis and an audit, and fix findings.
-
Rehearse
Run the exact deployment against a mainnet fork, then on Sepolia, and test the result.
-
Prepare
Record compiler settings, fund a dedicated deployer, check gas prices and set constructor parameters.
-
Deploy
Deploy with Ignition from a tagged commit, so the deployment is recorded and resumable.
-
Verify
Verify source on Etherscan and Sourcify.
-
Hand over control
Transfer ownership and administrative roles to a multisig, possibly behind a timelock, and revoke deployer privileges.
-
Monitor
Watch transactions and events, and announce the addresses through official channels.
Launching on mainnet
A key in a repository
A developer accidentally pushes a hardhat.config.js containing a testnet private key to a public repository and deletes it in the next commit an hour later. The account only ever held Sepolia ether. What should they do?
Treat the key as compromised: stop using it, create a new account and move any remaining assets. Check whether the same key or mnemonic is used on mainnet or other chains, because bots check every network. Change the configuration to use configVariable with the keystore so that keys never appear in files again.
Who should own the contract?
After a mainnet deployment, the token's Ownable owner is the deployer, a hot wallet on a developer's laptop. Why is this a risk, and what should happen next?
Whoever compromises that laptop can mint, pause or upgrade. Ownership should move to a multisig, such as a 3-of-5 Safe held by different people on hardware wallets, using Ownable2Step so the multisig must accept, and administrative changes should go through a timelock so users can see them coming.
Name four things that must match for source verification to succeed.
Show answer
The source code, the compiler version, the compiler settings (optimizer, runs, EVM version, viaIR) and the constructor arguments used at deployment.
Exam Tips
Remember for the exam
- Verification needs identical source, compiler version, settings and constructor arguments.
- npx hardhat verify or ignition deploy --verify publish source to explorers.
- Keep secrets in the Hardhat keystore or environment variables, never in the repository.
- Rehearse on a fork and Sepolia; transfer ownership to a multisig after deployment.