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 do so 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 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:

Successfully submitted source code for contract
contracts/Lock.sol:Lock at 0xC44De7f82f93799a8E405DF3221AfB115B4E7e45
for verification on the block explorer. Waiting for verification result...

Successfully verified contract Lock on the block explorer.
https://goerli.lineascan.build/address/address/0xC44De7f82f93799a8E405DF3221AfB115B4E7e45#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.