2

I have a mnemonic in my .env.

I added it to my hardhat.config.js as such:

accounts: {
    mnemonic: process.env.MNEMONIC,
    path: "m/44'/60'/0'/0",
    initialIndex: 0,
    count: 20,
    passphrase: "",
}

However, all my contracts are still being deployed by the 1st signer in getSigners().

Questions:

  1. How do I deploy all my contracts from the 1st address generated by my mnemonic (without having to write .connect() for each ContractFactory)? Essentially, how do I change the default signer?
  2. How do I get multiple signers from my one mnemonic?
1
  • Not 100% sure, but i think there is no way to change the default signer, that's why the .connect method was introduced.
    – Akall
    Feb 28 at 19:13

1 Answer 1

1

There are a couple of ways to change the default deployer.

  • Changing the starting index

You can change the default by increasing the initialIndex in the accounts section of the configuration file.

accounts: {
  mnemonic: process.env.MNEMONIC,
  path: "m/44'/60'/0'/0",
  initialIndex: 1,           // <---- start with index 1
  count: 20,
  passphrase: "",
}
  • Configure the signer when getting the contract factory

The getContractFactory accepts a signer as second parameter.

const [firstAccount, secondAccount, thirdAccount] = await ethers.getSigners();

const Lock = await ethers.getContractFactory("Lock", thirdAccount);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.