Skip to content

Commit 12d4f93

Browse files
committed
feat: allow to mnemonic or private key and choose whether to use hosted or remote keys for a fork
1 parent 4953cae commit 12d4f93

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

hardhat.config.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ const networkConfigs: NetworkConfig[] = [
6262
{ network: 'kovan', chainId: 42 },
6363
]
6464

65-
function getAccountMnemonic() {
66-
return process.env.MNEMONIC || ''
65+
function getAccountsKeys() {
66+
if (process.env.MNEMONIC) return { mnemonic: process.env.MNEMONIC }
67+
if (process.env.PRIVATE_KEY) return [process.env.PRIVATE_KEY]
68+
return 'remote'
6769
}
6870

6971
function getDefaultProviderURL(network: string) {
@@ -77,9 +79,7 @@ function setupNetworkProviders(hardhatConfig) {
7779
url: netConfig.url ? netConfig.url : getDefaultProviderURL(netConfig.network),
7880
gas: netConfig.gas || 'auto',
7981
gasPrice: netConfig.gasPrice || 'auto',
80-
accounts: {
81-
mnemonic: getAccountMnemonic(),
82-
},
82+
accounts: getAccountsKeys(),
8383
}
8484
}
8585
}
@@ -135,9 +135,8 @@ const config: HardhatUserConfig = {
135135
hardfork: 'london',
136136
},
137137
localhost: {
138-
accounts: {
139-
mnemonic: DEFAULT_TEST_MNEMONIC,
140-
},
138+
accounts:
139+
process.env.FORK === 'true' ? getAccountsKeys() : { mnemonic: DEFAULT_TEST_MNEMONIC },
141140
},
142141
},
143142
etherscan: {

0 commit comments

Comments
 (0)