My hardhat.config.js
declares networks and accounts:
require('dotenv').config();
module.exports = {
solidity: "0.8.10",
networks: {
goerli: {
url: `https://goerli.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [process.env.PRIVATE_KEY, process.env.DEFAULT_MEMBER_PRIVATE_KEY, process.env.TEST_MEMBER_PRIVATE_KEY]
},
sepolia: {
url: `https://sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: [process.env.PRIVATE_KEY, process.env.DEFAULT_MEMBER_PRIVATE_KEY, process.env.TEST_MEMBER_PRIVATE_KEY]
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
};
I would have thought that ethers.getSigners()
returns this list of configured accounts, but while testing it, it returned a list of accounts, among which there were NO accounts I've configured for the above networks.
Since I need those signers when writing tests, how to acually get a list of signers for configured accounts (and only those)?
And second question: what are those signers returned by getSigner()
?
Since your question doesn't specify how you run the test, I'm assuming you're using the npx hardhat test
command with no additional arguments and options.
In that case, the default hardhat
network (emulator) is used for the test. It's instantiated before the test starts and destructed after the test ends so it doesn't affect the state of other runs.
This network contains 20 prefunded and unlocked accounts generated from a predetermined mnemonic. The default values are available in the docs page, and you can override them in the config. For example specify your custom prefunded and unlocked accounts from private keys instead of the default mnemonic.
networks: {
hardhat: {
accounts: [
{privateKey: "0x...", balance: "1000000000000000000000"}
]
}
}