1

Here's my hardhat.config.ts file

{
      defaultNetwork: 'goerli', //////// here 'polygon_mumbai'
      networks: {
        hardhat: {
        },
        localhost : {
          url : 'http://127.0.0.1:8545',
          accounts : [local_network_pvk]
        },
        goerli: {
          url: 'etH_RPC_URL_HERE',
          accounts: [admin_private_key_eth],
        },
        polygon_mumbai: {
          url: 'POLYGON_RPC_URL',
          accounts: [admin_private_key_eth],
        },
      },
      solidity: {
        version: '0.8.17',
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
      paths: {
        sources: "./src/blockchain-utils/ethereum/contracts",
        tests: "./src/blockchain-utils/ethereum/test",
        cache: "./src/blockchain-utils/ethereum/cache",
        artifacts: ".src/blockchain-utils/ethereum/hh-artifacts"
      },
      mocha: {
        timeout: 40000
      }
    };

I want to run smart contracts of both Polygon and Eth how to configure the hardhatconfig file???

2 Answers 2

0

It is not possible to have multiple default networks in your hardhat.config.js. The defaultNetwork is used to specify which network should be used, in case there is no network specified when you execute npx hardhat ... in your terminal. The defaultNetwork needs to be configured in the networks object, like in the example code you provided (the defaultNetwork is set to goerli).

If you want to run another network than the default one, you can just run npx hardhat run --network goerli ... or npx hardhat run --network polygon_mumbai ...

Additionally: you also can't run multiple networks simultaneously within a single command in hardhat, but you can run each network in separate terminals. You can run a script for the polygon_mumbai network in one terminal, and then run a different script for the goerli network in another terminal.

1
  • There is a npm package named "hardhat-change-network" we can use that to change the Network using Script without using cli
    – user114704
    Feb 7 at 8:42
0

There is a npm package named "hardhat-change-network" we can use that to change the Network using Script without using cli Just install and use : hre.changeNetwork('goerli');

Your Answer

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

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