>
>
Complete the 2023 Solidity Survey here
>
>

#Verifying your deployment

Once your Ignition module is tested and ready, the next step is to deploy it to a live network and verify the source code of each of its contracts.

Verifying a contract means making its source code public, along with the compiler settings you used, which allows anyone to compile it and compare the generated bytecode with the one that is deployed on-chain. Doing this is extremely important in an open platform like Ethereum.

In this guide we'll explain how to do this with the Etherscan explorer.

# Getting an API key from Etherscan

The first thing you need is an API key from Etherscan. To get one, go to their site, sign in (or create an account if you don't have one) and open the "API Keys" tab. Then click the "Add" button and give a name to the API key you are creating (e.g. "Hardhat"). After that you'll see the newly created key in the list.

Open your Hardhat config and add the API key you just created:

TypeScript
JavaScript
export default {
  // ...rest of the config...
  etherscan: {
    apiKey: "ABCDE12345ABCDE12345ABCDE123456789",
  },
};
module.exports = {
  // ...rest of the config...
  etherscan: {
    apiKey: "ABCDE12345ABCDE12345ABCDE123456789",
  },
};

# Deploying and verifying on the Sepolia testnet

We are going to use the Sepolia testnet to deploy and verify our Ignition module, so you need to add this network in your Hardhat config. Here we are using Alchemy to connect to the network.

TIP

For more information on vars and configuration variables, please see our configuration variables guide.

TypeScript
JavaScript
// Go to https://alchemy.com, sign up, create a new App in
// its dashboard, and set the Hardhat configuration variable
// ALCHEMY_API_KEY to the key
const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY");

// Replace this private key with your Sepolia test account private key
// To export your private key from Coinbase Wallet, go to
// Settings > Developer Settings > Show private key
// To export your private key from Metamask, open Metamask and
// go to Account Details > Export Private Key
// Beware: NEVER put real Ether into testing accounts
const SEPOLIA_PRIVATE_KEY = vars.get("SEPOLIA_PRIVATE_KEY");

export default {
  // ...rest of your config...
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
      accounts: [SEPOLIA_PRIVATE_KEY],
    },
  },
};
// Go to https://alchemy.com, sign up, create a new App in
// its dashboard, and set the Hardhat configuration variable
// ALCHEMY_API_KEY to the key
const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY");

// Replace this private key with your Sepolia test account private key
// To export your private key from Coinbase Wallet, go to
// Settings > Developer Settings > Show private key
// To export your private key from Metamask, open Metamask and
// go to Account Details > Export Private Key
// Beware: NEVER put real Ether into testing accounts
const SEPOLIA_PRIVATE_KEY = vars.get("SEPOLIA_PRIVATE_KEY");

module.exports = {
  // ...rest of your config...
  networks: {
    sepolia: {
      url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
      accounts: [SEPOLIA_PRIVATE_KEY],
    },
  },
};

To deploy on Sepolia you need to send some Sepolia ether to the address that's going to be making the deployment. You can get testnet ether from a faucet, a service that distributes testing-ETH for free. Here is one for Sepolia:

TIP

This guide assumes you are using the contracts and Ignition module from the quick start guide, but the steps are the same for any deployment.

Now you are ready to deploy your module to the testnet, but first we are going to make the source code of our contract unique. The reason we need to do this is that the sample code from the quick start guide is already verified in Sepolia, so if you try to verify it you'll get an error. If you are using your own contracts, you can likely skip this step.

Open your contract and add a comment with something unique, like your GitHub's username. Keep in mind that whatever you include here will be, like the rest of the code, publicly available on Etherscan:

// Author: @janedoe
contract Rocket {

You can now run the deployment using the newly added Sepolia network:

TypeScript
JavaScript
npx hardhat ignition deploy ignition/modules/Apollo.ts --network sepolia --verify
npx hardhat ignition deploy ignition/modules/Apollo.js --network sepolia --verify

The --verify flag is optional, but it tells Hardhat Ignition to verify the contracts after a successful deployment.

If you have an existing deployment and want to verify it, you can also run the verify task directly by passing the deployment ID:

npx hardhat ignition verify chain-11155111

TIP

If you get an error saying that the address does not have bytecode, it probably means that Etherscan has not indexed your contract yet. In that case, wait for a minute and then try again.

After the task has successfully executed, for each deployed contract you'll see a link to its publicly verified code.

To learn more about verifying, read the hardhat-verify documentation.