VERIFY CONTRACTS USING HARDHAT
Last updated
Last updated
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
Run npx hardhat
in your project folder and follow the instructions to create ().
Install the (requires v3.0.0+).
npm
yarn
Add the following statement to your hardhat.config.js
.
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 ID
Gather Mainnet: 192837465
Gather Testnet: 356256156
apiURL
- Block explorer API URL
Gather Mainnet: https://explorer.gather.network/api
Gather Testnet: https://testnet-explorer.gather.network/api
browserURL
- Block explorer URL
Gather 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:
You can include constructor arguments with the verify task
Without constructor arguments
Complex constructor arguments
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):
Go to Gather explorer and paste the contract address into the search bar. If verified, the code tab will display a green checkmark.
If using TypeScript, add this to your hardhat.config.ts.
.
Your basic (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. .
If you prefer, you can migrate to to use a plugin bundle.
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 . For example, if you have a contract like this: