-
-
Notifications
You must be signed in to change notification settings - Fork 559
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
auto verify smart contracts functionality while deploying #64
Conversation
This feature should be designed to be optional imo, and should not throw an error for an empty etherscan API key. |
Thank you for this suggestion, I didn't think of it this way. Let's see what is review from Paul. |
I'm willing to merge this, but there should be some changes before I do that.
|
I'll surely update these mentioned things and try once again, thank you for the guidance. Should I close this PR, update the code and make another PR for review ? |
No. You can |
Thank you @PaulRBerg |
Hey @PaulRBerg , I refactored the code using the programmatic verify:verify subtask, please review. |
const greeterFactory: Greeter__factory = await ethers.getContractFactory("Greeter"); | ||
const greeter: Greeter = <Greeter>await greeterFactory.deploy(taskArguments.greeting); | ||
await greeter.deployed(); | ||
console.log("Greeter deployed to: ", greeter.address); | ||
|
||
if (network.name !== "hardhat" && config.etherscan.apiKey) { | ||
await run("verify:verify", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, if we call verify on etherscan right after contract deployment it will be always failed due to etherscan need time to load the smart contract code either. Then we should delay some minutes before invoke verification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, yes I researched about this and I'll make it wait for atleast 1-2mins after deployment so etherscan could do it's stuff in the meantime. Thank you for the correction!
Edit: you can actually just install for what it's worth, if you enable the here is a script that will upload your build/contracts output provided that you have enabled Configuring Solc output: export const defaultSolcOutputSelection = {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata",
],
"": ["ast"],
}, see discussion here: NomicFoundation/hardhat#1863 - this may become the default in hardhat soon. |
I find
Thanks for the tip! I didn't know that. |
Just came across this discussion by chance.
This would be the easiest way if you are using For other cases it is a little manual: Truffle: If you are using truffle to deploy your contracts, you can provide the json file of the contract deployed at Compile in Hardhat and deploy manually: We have an easier verification for hardhat build outputs coming up, but for now, you'd have to
as stated. Then you'd need to extract the metadata of the contract at Happy to help if you have any questions regarding Sourcify! |
Thanks for your input, @kuzdogan. There has been a length discussion in #31 which at the time led me to believe that disabling the metadata hash is the best thing to do (since the template is aimed at newbies who might be confused by the impact of the metadata hash on the bytecode). But not supporting Sourcify out-of-the-box is not nice. I will reconsider this. Might be worth it to build a Hardhat plugin for Sourcify? |
As stated above hardhat-deploy has Sourcify support but a plugin would be as simple as calls to our API. I don't think we can focus on a seperate plugin for a while since + NomicFoundation/hardhat#1863 is merged so we are expecting hardhat to output metadata by default with the next release. Then our goal is to verify a contract at a given address and chain by only the output .json in |
@PaulRBerg i've built one recently (i.e. forked and updated a defunct one) in case you're interested: @xtools-at/hardhat-sourcify |
Used packages:
A contract with simple arguments can be easily verified directly without the need to running a verify command yourself. A contract with complex arguments can be verified too using automation, will also make a PR for that as well. I have tested both but only added a single feature in this PR.
Please review the code, looking forward for your response, Thank you so much!