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
npminstall--save-devhardhat
yarn instructions
yarnadd--devhardhat
2. Create a project
Run npx hardhat in your project folder and follow the instructions to create (more info here).
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:
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.
$ npx hardhat verify --network gathertestnet --constructor-args arguments.js 0x2e58ccAD9A7fF467Dc04C41389F18b92E7269319
Nothing to compile
Compiling 1 file with 0.8.17
Successfully submitted source code for contract
contracts/BatchTransferRewardDistributor.sol:BatchTransferRewardDistributor at 0x2e58ccAD9A7fF467Dc04C41389F18b92E7269319
for verification on the block explorer. Waiting for verification result...
Successfully verified contract BatchTransferRewardDistributor on Etherscan.
https://testnet-explorer.gather.network/api/address/0x2e58ccAD9A7fF467Dc04C41389F18b92E7269319#code