-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending hardhat-etherscan to support multiple API keys #1448
Comments
I was about to write an issue. You nailed it. 100% should need to support multiple api-keys on different networks. The only thing I would say is it could take the same format as "networks", i.e.
then you could do a
I agree that calling it etherscan works, but it would be way better to support .. I don't know
Cheers. |
Is there a good workaround for this? |
@frangio I was able to work around this by adding the module.exports = {
networks: {
mumbai: {
chainId: 80001, // <- add this
url: MUMBAI_API_URL,
},
},
}; With the After adding |
The config has been extended to allow both a string as api key or an object that can contain multiple api keys, keyed by network. Relates to #1448.
The config has been extended to allow both a string as api key or an object that can contain multiple api keys, keyed by chain. Relates to #1448.
The config has been extended to allow both a string as api key or an object that can contain multiple api keys, keyed by chain. Relates to #1448.
lol, it looks like Hardhat literally opened a PR as I was working on a hacky solution, but I figured I'd put it here just because I realized you could get around a bunch of this by having etherscan: {
apiKey: getApiKey()
}, and then use const getApiKey = () => {
switch (process.env.HARDHAT_NETWORK) {
case "mainnet" || "rinkeby" || "goerli" || "ropsten":
return process.env.ETHERSCAN_API_KEY;
case "polygon" || "mumbai":
return process.env.POLYGONSCAN_API_KEY;
case "fantom" || "fantom_testnet":
return process.env.FTMSCAN_API_KEY;
default:
return "";
}
} I haven't tested this out yet, so please let me know if this doesn't work like I think it does, but it seems valid. ofc, HH looks like they're working on something jucier, looking forward! |
@wschwab almost correct but does not respect the fall-through technique for multi-criteria. Here's a proper fix: const getApiKey = () =>
switch (process.env.HARDHAT_NETWORK) {
case "mainnet":
case "rinkeby":
case "goerli":
case "ropsten":
return process.env.ETHERSCAN_API_KEY;
case "polygon":
case "mumbai":
return process.env.POLYGONSCAN_API_KEY;
default:
return "";
}
} Another solution, since you'd use the same apiKey for multiple networks would be to create 2 |
Blockscout has just merged an (apparently) Etherscan-compatible API for verification: blockscout/blockscout#4908 |
This feature was (finally!) added in Check the release notes to learn more, or read this section of the docs. |
@fvictorio I checked out the feature but it does not seem to work for etherscan: {
apiKey: {
mainnet: process.env.ETHERSCAN_API_KEY,
rinkeby: process.env.ETHERSCAN_API_KEY,
polygon: process.env.POLYGON_API_KEY,
polygonMumbai: process.env.POLYGON_API_KEY,
},
} This is my config but if I select the network of polygonMumbai I still receive following error:
UPDATEeverything works as expected! Upgraded, removed node_modules and after cleaned install everything worked. |
Should not this be just mumbai, not polygonMumbai in your construction: etherscan: { |
Are you meaning you absoluely need to upgrade to @nomiclabs/hardhat-etherscan@3.0.0 to let your multiple apiKey construction to work? I woulf not work on lowere versions of nomiclabs? |
I take it back, it should be exactly polygonMumbai: mumbai: { etherscan: { |
@villarode yes you need to upgrade to version |
Many thanks mate, worked out perfectly!))
…On Sun, 6 Feb 2022, 20:00 John Kane, ***@***.***> wrote:
@villarode <https://github.com/villarode> yes you need to upgrade to
version 3.0.0 to take advantage of multiple api keys.
—
Reply to this email directly, view it on GitHub
<#1448 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ARYOXWTWANCNTH3KTHBUIBLUZ2SMRANCNFSM44O24W4Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
What about using custom networks? How can I verify in multiple custom networks at the same time? |
@ESNJS how to use custom networks is explained in the readme. Verifying in multiple networks at the same time is not supported at the moment. Feel free to open a new issue with that feature request. |
Extending
hardhat-etherscan
to support multiple API keysSummary:
The
hardhat-etherscan
plugin currently provides an interface to provide one API key for auto-verification. In the current ecosystem there is a need for being able to support multiple API keys. This feature request looks at howhardhat-etherscan
works now, and outlines potential solutions.Current structure of
hardhat-etherscan
The
hardhat-etherscan
enables auto-verification via anetherscan
object inhardhat.config
:(code taken from docs for
hardhat-etherscan
)Problems
In today's ecosystem, Etherscan has spun off block explorers for popular sidechains such as BSC (BSCScan) and Fantom (FTMScan), making the naming convention of the plugin itself slightly misleading. This recommends renaming in future versions to
hardhat-verification
. If Blockscout explorers become available, this will be doubly true.In addition, calling the object in the config
etherscan
has the same concern.Neither of these are meant to be the primary issue, though. The larger issue is that the
etherscan
object can only hold one API key at a time (viaetherscan.apiKey
). It would be valuable for projects deploying in multiple ecosystems to support multiple API keys.Proposed Solutions
1. Long-term proposal
In the long term we would like to recommend renaming the plugin to
hardhat-verification
, and replacing theetherscan
object in the config withexplorerApiKeys
, with the key being the name of a supported block explorer, something akin to:Renaming the plugin and the object has the added benefit of backwards compatability - the
hardhat-etherscan
and correspondingetherscan
object could remain supported without conflict.This could in turn involve code on the backend matching block explorers with
chainId
s, so that Hardhat knows, for example, to match achainId
of 56 with Binance Smart Chain. (This would likely mean giving the key values of block explorers, as in the example above). Alternatively, the name of the key could be matched with networks provided in thenetworks
object (in which case, instead of the keys above, they would carry the same name as the networks, for examplebsc
orfantom
). This would likely be an inferior option, as it would require pasting the same key multiple times in order to cover testnets. (Especially in the case of Ethereum/Etherscan, it could require separate mainnet, Ropsten, Rinkeby, Kovan, and Goerli keys, even though all work with the same Etherscan API key.)2. Short-term proposal
The most urgent item imho is supporting multiple API keys. Without introducing a new name and new structure, the current
hardhat-etherscan
plugin could be extended to support multiple keys by introducing anadditionalNetworks
object into theetherscan
object:Here the keys in
additionalNetworks
could be matched to the names of provided networks. This would require providing the same key for, say, BSC's main and test networks, as mentioned above, but does not have the same overhead as Etherscan (also mentioned above), and might be acceptable.Closing
This doesn't include the particulars of implementing any of the ideas here. I also don't intend for the suggested naming conventions and structures to be written in stone - there very well may be better ways to name or structure this. I'd be happy to work on a potential PR for this.
Thanks for taking the time to read this, and I'm looking forward to the feedback!
The text was updated successfully, but these errors were encountered: