Lesson 4 of 4 Deploying Smart Contracts

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.

Etherscan
TypeCommercial block explorer
NeedsAn API key
ShowsSource, ABI, Read and Write Contract tabs
Sourcify
TypeOpen, decentralised verification repository
NeedsNo key
ShowsExact match or match status (formerly full and partial match)
Blockscout
TypeOpen-source block explorer
NeedsDepends on the instance
ShowsSource and interaction tabs
npx hardhat verify --network sepolia 0xYourContract "0xOwnerAddress"
npx hardhat ignition deploy ignition/modules/ClubModule.js --network sepolia --verify

npx 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.

Scenario questions

Why verification fails

Exam skills 4.3.1

Diagnose source verification failures.

Log in to try this activity Interactive activities are free with an account.

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 configVariable with the Hardhat keystore (encrypted) or environment variables; older projects used .env files, 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.

Sort into groups

Safe with secrets?

Exam skills 4.3.2

Decide whether each practice keeps deployment secrets safe.

Log in to try this activity Interactive activities are free with an account.

A production deployment checklist

Teams typically follow a sequence like the following for a mainnet launch.

  1. Freeze and review

    Freeze the code, complete tests, static analysis and an audit, and fix findings.

  2. Rehearse

    Run the exact deployment against a mainnet fork, then on Sepolia, and test the result.

  3. Prepare

    Record compiler settings, fund a dedicated deployer, check gas prices and set constructor parameters.

  4. Deploy

    Deploy with Ignition from a tagged commit, so the deployment is recorded and resumable.

  5. Verify

    Verify source on Etherscan and Sourcify.

  6. Hand over control

    Transfer ownership and administrative roles to a multisig, possibly behind a timelock, and revoke deployer privileges.

  7. Monitor

    Watch transactions and events, and announce the addresses through official channels.

Put in order

Launching on mainnet

Exam skills 4.3.1 · 4.3.2

Arrange the steps of a mainnet launch.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Worked example

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.

Check yourself

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.