From 2e23ae3b585e3257db7dd249d7b52d3cce493033 Mon Sep 17 00:00:00 2001 From: def-main Date: Mon, 20 Dec 2021 20:34:10 -0800 Subject: [PATCH 1/2] Allow private key to be used with hardhat config --- hardhat.config.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index b98ea3c..114092f 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -26,6 +26,7 @@ const SKIP_LOAD = process.env.SKIP_LOAD === 'true'; const ALCHEMY_KEY = process.env.ALCHEMY_KEY || ''; const MNEMONIC = process.env.MNEMONIC || ''; const MNEMONIC_PATH = "m/44'/60'/0'/0"; +const HARDHAT_PRIVATE_KEY = process.env.HARDHAT_PRIVATE_KEY || ''; // Load hardhat tasks. if (!SKIP_LOAD) { @@ -47,15 +48,26 @@ function getRemoteNetworkConfig( networkName: NetworkName, networkId: number, ): HttpNetworkUserConfig { - return { - url: `https://eth-${networkName}.alchemyapi.io/v2/${ALCHEMY_KEY}`, - chainId: networkId, - accounts: { + let accounts; + if (MNEMONIC) { + accounts = { mnemonic: MNEMONIC, path: MNEMONIC_PATH, initialIndex: 0, count: 10, - }, + }; + } else if (HARDHAT_PRIVATE_KEY) { + accounts = [HARDHAT_PRIVATE_KEY]; + } else { + throw new Error( + 'hardhat.config.ts: Network requires either MNEMONIC or HARDHAT_PRIVATE_KEY ' + + 'to be specified', + ); + } + return { + url: `https://eth-${networkName}.alchemyapi.io/v2/${ALCHEMY_KEY}`, + chainId: networkId, + accounts, }; } From adc2142d91b6dcf19e133bb700d9ff35255ddb4c Mon Sep 17 00:00:00 2001 From: def-main Date: Mon, 20 Dec 2021 20:39:57 -0800 Subject: [PATCH 2/2] Fix hardhat compile --- hardhat.config.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 114092f..203b5d6 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -49,20 +49,15 @@ function getRemoteNetworkConfig( networkId: number, ): HttpNetworkUserConfig { let accounts; - if (MNEMONIC) { + if (HARDHAT_PRIVATE_KEY) { + accounts = [HARDHAT_PRIVATE_KEY]; + } else if (MNEMONIC) { accounts = { mnemonic: MNEMONIC, path: MNEMONIC_PATH, initialIndex: 0, count: 10, }; - } else if (HARDHAT_PRIVATE_KEY) { - accounts = [HARDHAT_PRIVATE_KEY]; - } else { - throw new Error( - 'hardhat.config.ts: Network requires either MNEMONIC or HARDHAT_PRIVATE_KEY ' + - 'to be specified', - ); } return { url: `https://eth-${networkName}.alchemyapi.io/v2/${ALCHEMY_KEY}`,