Hardhat Deployment – How to Deploy with Specific Account Using Hardhat

contract-deploymentethers.jshardhathardhat-deploy

I am trying to find out is it possible to set specific account from which to deploy contract in hardhat.

Does hardhat supports this by default or I need to include some other package.

Best Answer

Can you try this?

[theDefaultDeployer, acc1] = await ethers.getSigners();

// we will not use the "theDetaultDeployer" in what follows:
const MyContract = await ethers.getContractFactory("MyContract");
myContract = await MyContract.connect(acc1).deploy(1000);

// let's test it:
expect(await myContract.owner()).to.not.equal(theDefaultDeployer);
expect(await myContract.owner()).to.equal(acc1.address);

Notice the ".connect(acc1)" part that connects you to account 1 before deploying. This changes the default to any account you want (here, the second account in the "getSigners()" returned list).

Related Topic