Skip to content
This repository was archived by the owner on Oct 31, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ TEST_PRIVATE_KEY=

ALCHEMY_KEY=

INFURA_KEY=

ETHERSCAN_API_KEY=
27 changes: 21 additions & 6 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,33 @@ let testPrivateKey: string = process.env.TEST_PRIVATE_KEY || "";
let alchemyKey: string = process.env.ALCHEMY_KEY || "";
let etherscanKey: string = process.env.ETHERSCAN_API_KEY || "";
let polygonscanKey: string = process.env.POLYGONSCAN_API_KEY || "";
let infuraKey: string = process.env.INFURA_KEY || "";

function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
if (!alchemyKey) {
throw new Error("Missing ALCHEMY_KEY");

// if not using infura there better be an alchemy key or else fail
if(!infuraKey) {
if (!alchemyKey) {
throw new Error("Either ALCHEMY_KEY or INFURA_KEY must be defined");
}
}

const polygonNetworkName = network === "polygon" ? "mainnet" : "mumbai";

let nodeUrl =
chainIds[network] == 137 || chainIds[network] == 80001
? `https://polygon-${polygonNetworkName}.g.alchemy.com/v2/${alchemyKey}`
: `https://eth-${network}.alchemyapi.io/v2/${alchemyKey}`;
let nodeUrl;

// if polygon network then use appropriate alchemy/infura URL
if(chainIds[network] == 137 || chainIds[network] == 80001) {
if(alchemyKey) {
nodeUrl = `https://polygon-${polygonNetworkName}.g.alchemy.com/v2/${alchemyKey}`;
} else if(infuraKey){
nodeUrl = `https://polygon-${polygonNetworkName}.infura.io/v3/${infuraKey}`;
}
} else if(alchemyKey) {
nodeUrl = `https://eth-${network}.alchemyapi.io/v2/${alchemyKey}`;
} else if(infuraKey){
nodeUrl = `https://${network}.infura.io/v3/${infuraKey}`
};

return {
chainId: chainIds[network],
Expand Down