wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 293 forks source link

Support custom EVM network #291

Open NanezX opened 2 years ago

NanezX commented 2 years ago

Our project need to handle multi-chain deployment. I write a deploy script to "normal" EVM chains like Polygon, Binance, etc. But we need to support deployments to chains like Reef and Astar for ex. I really like hardhat-deploy and i want to continue use it to those deployments.

The problem is that, for example Reef blockchain, have they own hardhat-reef plugin to use with hardhat. Currently, they extends stuff to configuration and the signers, chainId, provider, etc, are obtained a little different. Idk if exist support to this in any way. I know when run the deploy task, the chainId is tried to be obtained, and that is not posible with the normal way.

There are a lot of chains that we want to deploy in our roadmap that have their "peculiarity" to deploy with hardhat. Basically, idk if there a way to handle those scenarios, because i would like to use this and the features when deploy.

Is there any way to handle this or override those funcionalities? I need changes some of them, like getChainId, getAccounts, provider...

The only way that i can deploy is write my own deploy script but without any of features of the hardhat-deploy. So if there no support for something that i describe, i'll have to replicate the feature that save the deployment to they own folder atleast

Hopefully i explained myself correctly (english is not my native language). Thanks for your job :)

wighawag commented 2 years ago

Hey @NanezX thanks for creating this issue.

It feels to me like this should be solved at a lower level. hardhat plugin system is not very extensible but I ll push hardhat to improve there so we can for example modify the rpc request.

This would let you create a plugin that would make hardhat-deploy work on your chain.

Though I am not exactly sure of the incompatibility you are talking about. maybe you have concrete example ?

hardhat-deploy is working on zksync support and this required changes to hardhat-deploy, but ideally I would have prefered for this to be done at a lower level. If that is not possible, hardhat-deploy could expose hooks.

NanezX commented 2 years ago

Thanks for answering.

Yeah, i can provide some examples about how Reef work with their own plugin called @reef-defi/hardhat-reef. This plugin handle the RPC, provider, and signers. One of the peculiarities in this chain with the plugin is on Signers. They have a reefSigner type since use mnemonic instead private keys to each account, is compatible with hardhat yes. That is already handle it by the reef plugin.

Another example is - we cannot acces to the provider as normal. It is necessary create the this with the endpoint or url that we have in the hardhat config. There are the reef_mainnet and reef_testnet. In this same way, we need to get first the provider if we want to call getChainId() or access to the network in hardhat config.

All this features are made through the HardhatRuntimeEnvironment because reef is extended to here:

// This get all the signers defined in seeds fields (which is the equivalent to accounts in Reef)
const signers = await hre.reef.getSigners()
// Get the address of the signer
const address1 = await signers[0].getAddress();
// Get the signer `deployer` if it is specified in the network config
const deployer = await hre.reef.gerSignerByName("deployer ");

// - Contracts
// Get the factory of contract named "Greeter"
const GreteerFactory = await hre.reef.getContractFactory("Greteer");
const greeter = await GreteerFactory.deploy();
// Get a contract with a address
const contract = await hre.reef.getContractAt(GreteerFactory, greeter.address);

Those examples are how reef plugin work in surface of course, but show the differences.

I know this can be too much (idk). But i feel that i can handle it in some way, still using the features that i want and have the repo as deploy multichain. In any case, if you can point me in right direction, I'm for sure able to try it.

wighawag commented 2 years ago

Just a quick reply

"I would have prefered for this to be done at a lower level"

Basically, having the reef plugin made to hijack call to eth_sendRawTransaction to implements its own signing, so other plugon do not need to care.

NanezX commented 2 years ago

Ok, I'll work on it and let you know if I got stuck or something. Thanks

stavalfi commented 1 year ago

hi, is there an update? 👯

zksync is on testnet! soon mainnet!