fix: conditionally register live networks only when ALCHEMY_API_KEY is set

This commit is contained in:
2026-05-29 15:43:39 -03:00
parent aa96fd89da
commit 1addaae1c7

View File

@@ -33,25 +33,31 @@ const chainIds = {
function getChainConfig( function getChainConfig(
chain: keyof typeof chainIds, chain: keyof typeof chainIds,
): NetworkUserConfig { ): NetworkUserConfig {
if (!alchemyApiKey) { let jsonRpcUrl =
throw new Error( "https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
`Please set ALCHEMY_API_KEY in a .env file before targeting ${chain}`,
);
}
let jsonRpcUrl = "https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
return { return {
// Comment out for default hardhat account settings
accounts: { accounts: {
count: 10, count: 10,
mnemonic, mnemonic,
path: "m/44'/60'/0'/0", path: "m/44'/60'/0'/0",
}, },
// gasPrice: 8000000000,
chainId: chainIds[chain], chainId: chainIds[chain],
url: jsonRpcUrl, url: jsonRpcUrl,
}; };
} }
const liveNetworks: Record<string, NetworkUserConfig> =
alchemyApiKey
? {
mainnet: getChainConfig("mainnet"),
sepolia: getChainConfig("eth-sepolia"),
polygon: getChainConfig("polygon-mainnet"),
arbitrum: getChainConfig("arb-mainnet"),
rootstock: getChainConfig("rootstock"),
rsktestnet: getChainConfig("rootstock-testnet"),
}
: {};
const config: HardhatUserConfig = { const config: HardhatUserConfig = {
defaultNetwork: "hardhat", defaultNetwork: "hardhat",
etherscan: { etherscan: {
@@ -94,13 +100,7 @@ const config: HardhatUserConfig = {
mnemonic, mnemonic,
}, },
}, },
// network: getChainConfig("{INSERT_NAME}"), ...liveNetworks,
mainnet: getChainConfig("mainnet"),
sepolia: getChainConfig("eth-sepolia"),
polygon: getChainConfig("polygon-mainnet"),
arbitrum: getChainConfig("arb-mainnet"),
rootstock: getChainConfig("rootstock"),
rsktestnet: getChainConfig("rootstock-testnet"),
}, },
paths: { paths: {
artifacts: "./artifacts", artifacts: "./artifacts",