I have a piece of code that deploys a contract. I would like to deploy this contract to two networks (lets say Goerli and MainnetEthereum). Inside a loop in hardhat script I can change the network using the following code:

for (const currNetwork of networksToDeploy) {
   const DToken = await DToken.deploy(...constructorArgs)

The network doesn't change, it double deploys it in Goerli (the first network). The loop is changing correctly but the provider on DToken.deploy stays the same. Any ideas on how to change that?

2 Answers 2


You need to instantiate two Wallets.


To create a Wallet you need to provide a private key and a provider (if desired) to instantiate a wallet.

new ethers.Wallet( privateKey [ , provider ] )

Here is an example code to instantiate two wallets:

const walletGoerli = new ethers.Wallet(privateKey, goerliProvider);
const walletMumbai = new ethers.Wallet(privateKey, mumbaiProvider);

I managed to be able to deploy cross-chain using xDeployer:

By adding the settings to the hardhat.js and then running npx hardhat xdeploy.

More info is available in their documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.