NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7k stars 1.36k forks source link

`hardhat init` by cloning on-chain verified contracts #5397

Open Troublor opened 3 weeks ago

Troublor commented 3 weeks ago

Describe the feature

We propose to bring the clone on-chain verified contracts feature to hardhat to facilitate daily development, learning, and experimenting of Ethereum developers.

Motivation

Currently hardhat init creates only sample projects. This creates an obstacle on blockchain developers, who may want to re-compile the contracts of popular DApps, customize it, deploy in a local chain, write hardhat tests/tasks with the contract, etc.

Proposal

We propose to extend the hardhat init command by providing one additional question during the project creation guide, e.g., Do you want to clone an existing on-chain contract?, to allow users to opt into the clone feature. This will dump contract source code from Etherscan or other sources into the hardhat project being created, and most importantly, the hardhat configuration will be adjusted according to the compilation settings for the on-chain contract.

We welcome any comments and suggestions helping us improve this feature and contribute to a better smart contract development and debugging experience.

Disclaimer

We (@ZhangZhuoSJTU and I) are planning to bring the clone on-chain verified contracts feature to hardhat, just as we did for foundry: https://github.com/foundry-rs/foundry/pull/7576. More information can be found at https://github.com/foundry-rs/foundry/issues/7575 The forge clone feature has received great feedback in the community. https://x.com/troublor/status/1780984367931695256 Now we are trying to bring this to hardhat.

Search terms

clone, init

Troublor commented 3 weeks ago

Would it be a good choice to fork the hardhat repo and modify the code of hardhat init's createProject() function?

Is the plugin capable of achieving this goal?

alcuadrado commented 3 weeks ago

Hey @Troublor! 👋

A plugin can't really customize the init functionality, but it can customize the config and define new tasks, so I think a hardhat clone <address> workflow would be possible, and easier to adapt by existing users.

Troublor commented 3 weeks ago

@alcuadrado Thanks for the clarification! The hardhat clone <address> workflow is definitely fine with us.

Is hardhat clone possible with plugin? Correct me if I am wrong: To my understanding, the plugin only works on an existing hardhat project, while hardhat clone needs to work as a global command (since it is used to create a hardhat project). So I think the solution is to directly add the clone subcommand to the hardhat core CLI.