I am currently learning the usage of the Hardhat deployment environment and I have some questions with regards to getSigners()

I understand that getSigners() is an abstraction of an eth acc to be used to sign messages and tx and send signed tx to the eth network

So in calling eg. const accounts = await ethers.getSigners() We will be returned a list of eth acc in the node we are connected to

This is the part which I am confused about:

What is the difference between the account we often save in our .env file (the one with the private key to our accounts when we set up hardhat.config.js) and accounts from getSigners()? Why isn't it the eth account in our .env responsible for signing tx?

Hope that you guys can help me out here:)

1 Answer 1


Your .env file is an option for defining secret information - such as account private keys. getSigners returns the list of available signers, which may come from multiple sources.

The tricky part is where do the signers come from? It really depends on your setup and used network. For example, in the hardhat (default) network the signers is based on a static list of private keys, meant for only testing purposes. I guess you can override these signers to be something from your .env file, but usually there's no need.

For other networks the signers depend on your setup - maybe you read them from .env or somewhere else.

  • 2
    "in the hardhat (default) network the signers is based on a static list of private keys" In this case, how can we reuse the same getSigners(0) in unit tests ? Setting [owner] = ..getSigners() in beforeEach doesn't seem to reset the balance for example.
    – gneric
    Commented Jan 3, 2022 at 22:02

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.