I'm trying to deploy a contract using the second address in my wallet (Metamask), how can I achieve such thing from hardhat? This is my hardhat config:

 * @type import('hardhat/config').HardhatUserConfig

module.exports = {
  solidity: "0.8.2",
  networks: {
    rinkeby: {
      url: `https://eth-rinkeby.alchemyapi.io/v2/${process.env.ALCHEMY_KEY}`,
      accounts: {mnemonic: process.env.MNEMONIC_WALLET},
      gas: 2100000,
      gasPrice: 80000000000
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY

In this way I deploy my contract using the first address of my Metamask wallet, how can I deploy the contract using the second one?

1 Answer 1


This is actually a question about ethers.js, not hardhat.

Let's use my Greeter deployer as a base to start from:

  .addParam("greeting", "Say hello, be nice")
  .setAction(async function (taskArguments: TaskArguments, { ethers }) {
    const signers: SignerWithAddress[] = await ethers.getSigners();
    const greeterFactory: Greeter__factory = <Greeter__factory>await ethers.getContractFactory("Greeter");
    const greeter: Greeter = <Greeter>await greeterFactory.connect(signers[0]).deploy(taskArguments.greeting);
    await greeter.deployed();
    console.log("Greeter deployed to: ", greeter.address);

So to change the deployer account, you use the connect method and then call the deploy function.

  • Thank you really much! This is the solution.
    – Allennick
    Commented Apr 6, 2022 at 13:20
  • Happy to help. Make sure to check my Solidity template, as a Hardhat user I think that you will like it a lot. Commented Apr 6, 2022 at 18:09

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.