When I try to deploy a contract on hardhat localhost and deploy two contracts they endup getting the same address

This is how I run hardhat

test@test:~/test$ npx hardhat node       
Started HTTP and WebSocket JSON-RPC server at

This is how I deploy

test@test:~/test$ npx hardhat run scripts/First/local/deploy.js
Contract successfully deployed. Contract address 0x5FbDB2315678afecb367f032d93F642f64180aa3
test@test:~/test$ npx hardhat run scripts/Second/local/deploy.js 
Contract successfully deployed. Contract address 0x5FbDB2315678afecb367f032d93F642f64180aa3

And this is the deployment script (both contracts are similar)

const { ethers } = require("hardhat")

async function main() {

    [owner] = await hre.ethers.getSigners()

    const TestNFT = await ethers.getContractFactory("TestNFT", owner)
    const testNFT = await TestNFT.deploy("TestNFT", "TNFT")

    await TestNFT.deployed()
        `Contract successfully deployed. Contract address ${testNFT.address}`

    .then(() => process.exit(0))
    .catch((error) => {

Not sure why this is happening, but each contract should have a different address... right?

1 Answer 1


So you are trying to run a Hardhat blockchain with npx hardhat node, connect to it and deploy two contract to it.

This depends on your Hardhat network configurations, but my guess is that the deployment is not using your running node at all. Check whether it lists deployments when those are happening. My guess is that you are using a Hardhat blockchain which is started just for the deployment, and killed right after that. And since it's started anew, it starts with the same settings and gives you the same first contract address (both contracts are new, from the blockchain's point of view, since it was restarted).

I guess you should be able to target the running node simply with the --network localhost setting, as is explained here: https://hardhat.org/guides/deploying

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.