Hardhat
To verify your Hardhat contracts, use Hardhat's Etherscan plugin to verify contracts on Lineascan.
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
in the Hardhat deployment instructions.
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
Obtain 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
These instructions verify using the Linea instance of Etherscan, which currently doesn't support Yul. If you would like to verify using Blockscout, please use the Blockscout API URL for the required network.
First, we'll need to add a custom chain like so:
- Mainnet
- Testnet
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/"
}
}
]
}
networks: {
linea_sepolia: {
...
}
},
etherscan: {
apiKey: {
linea_sepolia: LINEASCAN_API_KEY
},
customChains: [
{
network: "linea_sepolia",
chainId: 59141,
urls: {
apiURL: "https://api-sepolia.lineascan.build/api",
browserURL: "https://sepolia.lineascan.build/address"
}
}
]
}
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:
- Mainnet
- Testnet
npx hardhat verify --network linea_mainnet <DEPLOYED_CONTRACT_ADDRESS> <CONTRACT_ARGUMENTS>
npx hardhat verify --network linea_sepolia <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
If you get an error saying that the address doesn't 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.