Skip to main content

Hardhat

To verify your Hardhat contracts, you can use Hardhat's Etherscan plugin to verify contracts on Lineascan.

note

Note that this is included as part of the hardhat-toolbox plugin.

These steps assume you stored your secret keys in a .env file, which you can read more about here.

Download the plugin​

If you aren't already using @nomicfoundation/hardhat-toolbox, you can use @nomicfoundation/hardhat-verify instead. Find the instructions on how to add it to your project here.

Add your Lineascan API Key​

We'll be using a .env file to store our sensitive information. You can find instructions on how to set up the file here.

Next, you'll need to get a Lineascan (Linea instance of Etherscan) key by creating an account at https://lineascan.build/myapikey. Grab your key, and add it to the .env file:

LINEASCAN_API_KEY=YOUR_API_KEY_HERE

Then, add the key to your hardhat.config.js as follows:

const { PRIVATE_KEY, LINEASCAN_API_KEY } = process.env;

Add the custom chain​

note

These instructions verify using the Linea instance of Etherscan, which currently does not support Yul. If you would like to verify using Blockscout, please use the API URLs referenced here.

First, we'll need to add a custom chain like so:

networks: {
linea_mainnet: {
...
}
},
etherscan: {
apiKey: {
linea_mainnet: LINEASCAN_API_KEY
},
customChains: [
{
network: "linea_mainnet",
chainId: 59144,
urls: {
apiURL: "https://api.lineascan.build/api",
browserURL: "https://lineascan.build/"
}
}
]
}
note

The Etherscan apiKey and network name for your custom chain must match the network name under networks in your hardhat.config.js.

Verify the smart contract​

To verify your contract, run the following command:

npx hardhat verify --network linea_mainnet <DEPLOYED_CONTRACT_ADDRESS> <CONTRACT_ARGUMENTS>

You should see something that looks a little like this if verifying on Linea Sepolia:

npx hardhat verify --network linea_sepolia 0x3Af089fee468eb7fcf750e929321b0D7f7845f5C "1893456000"

[INFO] Sourcify Verification Skipped: Sourcify verification is currently disabled. To enable it, add the following entry to your Hardhat configuration:

sourcify: {
enabled: true
}

Or set 'enabled' to false to hide this message.

For more information, visit https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify
Successfully submitted source code for contract
contracts/Lock.sol:Lock at 0x3Af089fee468eb7fcf750e929321b0D7f7845f5C
for verification on the block explorer. Waiting for verification result...

Successfully verified contract Lock on the block explorer.
https://sepolia.lineascan.build/address/address/0x3Af089fee468eb7fcf750e929321b0D7f7845f5C#code
note

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 while and then try again.

You can check that it was verified correctly by navigating to the testnet block explorer or the mainnet block explorer and pasting in the deployed contract address.