8

I am finding it difficult to understand difference between these two.

2 Answers 2

10

getSigners and getNamedAccounts are both used for the same purpose, getting public key for accounts.

Since you asked for getNamedAccounts I assume you are developing on a hardhat environment because it is used to retrieve accounts manually from the attribute namedAccounts defined whithin hardhat.config.js and it is an exclusive feature with the plugin hardhat-deploy.

In the other hand a signer in ethers.js is an object that represents an Ethereum account. getSigners helps getting a list of the accounts in the node we're connected to, which is probably the Hardhat Network.

2
  • If I write getNamedAccounts instead of getSigners in my code, the code won't run. Here is my code link
    – amit
    Aug 15, 2022 at 9:30
  • 1
    getNamedAccounts configurations should be included in hardhat.config.js, u should have a similar code snippet. json module.exports = { ... namedAccounts: { deployer: { default: 0, }, }, ... }
    – jutsu
    Aug 15, 2022 at 22:19
3

If I write getNamedAccounts instead of getSigners in my code, the code won't run ?

Because you are using named accounts. That's why getNamedaccounts results in an error. Check your hardhat.config, looking from gist you may have a Named account variable as deployer.

2
  • Yeah right, i did!
    – amit
    Aug 15, 2022 at 15:25
  • javascript namedAccounts: { deployer: { default: 0, }, user: { default: 0, }, },
    – amit
    Aug 16, 2022 at 3:27

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.