VERIFY CONTRACTS USING HARDHAT
INSTALLATION
1. Install Hardhat
If you are starting from scratch, create an npm project by going to an empty folder, running npm init
, and following the instructions. Recommend npm 7 or higher.
Once your project is ready:
npm instructions
yarn instructions
2. Create a project
Run npx hardhat
in your project folder and follow the instructions to create (more info here).
3. Install plugin
Install the hardhat-etherscan plugin (requires v3.0.0+).
npm
yarn
4. Add plugin reference to config file
Add the following statement to your hardhat.config.js
.
If using TypeScript, add this to your hardhat.config.ts.
More info on using typescript with hardhat available here.
CONFIG FILE
Your basic Hardhat config file (hardhat.config.js
or hardhat.config.ts
) will be setup to support the network you are working on. In this example we use the Gather test network and a .js
file.
Here we add an RPC url without an API key, however some value is still required. You can use any arbitrary string. More info.
If you prefer, you can migrate to hardhat-toolbox to use a plugin bundle.
Add Gather Network as custom chain
Now add gather mainnet and testnet as custom chain in the etherscan.
You can add a customChains
object to the config file. It includes:
chainID
- Network chain IDGather Mainnet:
192837465
Gather Testnet:
356256156
apiURL
- Block explorer API URLGather Mainnet:
https://explorer.gather.network/api
Gather Testnet:
https://testnet-explorer.gather.network/api
browserURL
- Block explorer URLGather Mainnet:
https://explorer.gather.network
Gather Testnet:
https://testnet-explorer.gather.network
This is how it would be added to the config file. The network name in customChains
must match the network name in the apiKey
object.
Note: The apiKey
can contain any random string as api key verification is not required for Gather, but it cannot be empty.
Your final hardhat config file (hardhat.config.js
or hardhat.config.ts
) should be like this:
DEPLOY AND VERIFY
Deploy
Verify
You can include constructor arguments with the verify task
Without constructor arguments
Complex constructor arguments
When the constructor has a complex argument list, you'll need to write a javascript module that exports the argument list. The expected format is the same as a constructor list for an ethers contract. For example, if you have a contract like this:
then you can use an arguments.js file like this:
The module can then be loaded by the verify
task when invoked like this:
Gather testnet example (complex constructor arguments):
CONFIRM VERIFICATION ON GATHER EXPLORER
Go to Gather explorer and paste the contract address into the search bar. If verified, the code tab will display a green checkmark.
Last updated