I've deployed a contract(MyContract) on both ethereum sepolia and arbitrum sepolia testnets.

 async function getContractAddress() {
    const { deployer } = await getNamedAccounts();
    const myContract = await ethers.getContract(
    console.log("Getting address of Contract...");
    const contractAddress = await myContract.getAddress();
      `My contract is deployed at ${contractAddress}`

In case of above function it looks for the contract on local hardhat node and fails to find any contract. How can I make it look for the contract on a specific network? Is there a way to get Contract address deployed on a particular chain via hardhat ethers? I'm looking for a way to do this via code, instead of CLI.

Please help me out. Thanks is advance.

1 Answer 1


While running your script, you can pass the network flag at the end of the command, like:

npx hardhat run scripts/yourScriptFileName.js —-network desiredNetworkName

You can pass the network name like eth-sepolia, arb-sepolia, etc., depending on the exact network names that you’ve used in your hardhat.config.js file.

  • I'm looking for a way to do this via code, instead of CLI. Commented May 12 at 4:42
  • Okay. Can you add your deployment script in your question? Commented May 12 at 8:01

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.