Search code examples
hardhat

Can I know which network a deployment script is running on?


When running a deployment script on Hardhat with a specified network

npx hardhat run scripts/deploy.ts  --network <network-name>

I want to get the <network-name> variable in the script so I could set different parameters for different chains. Is there a way to get that?


Solution

  • within your deploy script use:

    ethers.provider.network
    

    this will show you the chainId, which should be unique for every network, as well as the network name

    or alternatively read the runtime arguments

    hre.hardhatArguments