-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
798c634
commit 6592ded
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TNetworks } from "../../types/chains"; | ||
|
||
export const SUPPORTED_CHAINS: TNetworks = { | ||
testnet: { | ||
polygon: { | ||
name: "polygon", | ||
network: "polygon", | ||
blockExplorer: "https://mumbai.polygonscan.com/", | ||
nodeRPC: "https://matic-mumbai.chainstacklabs.com", | ||
chainId: 80001, | ||
mintContractAddress: "0xD96250D736642a487366170acd7823d8038Df212", | ||
currency: "MATIC", | ||
}, | ||
}, | ||
mainnet: { | ||
polygon: { | ||
name: "polygon", | ||
network: "polygon", | ||
blockExplorer: "https://polygonscan.com/", | ||
nodeRPC: "https://polygon-rpc.com/", | ||
chainId: 137, | ||
mintContractAddress: "0xCd494673999194365033D7A287af9f0a3b163874", | ||
currency: "MATIC", | ||
}, | ||
}, | ||
}; | ||
|
||
export const CHAINS_ENV = | ||
process.env.NODE_ENV === "production" | ||
? SUPPORTED_CHAINS.mainnet | ||
: SUPPORTED_CHAINS.testnet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ethers } from "ethers"; | ||
import { TChain } from "../../types/chains"; | ||
import { CHAINS_ENV } from "../config/chains"; | ||
import NFTABI from "../web3/abis/NFT.json"; | ||
class Web3Instance { | ||
public provider; | ||
|
||
constructor() { | ||
this.provider = new ethers.providers.JsonRpcProvider( | ||
CHAINS_ENV.polygon.nodeRPC | ||
); | ||
} | ||
|
||
public contract(chain: TChain = "polygon") { | ||
const network = this.getChainByName(chain); | ||
return new ethers.Contract( | ||
network.mintContractAddress, | ||
NFTABI, | ||
this.provider | ||
); | ||
} | ||
|
||
public getChainByName(chain: TChain = "polygon") { | ||
return CHAINS_ENV[chain]; | ||
} | ||
} | ||
|
||
export default Web3Instance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export type TChain = "polygon"; | ||
|
||
export interface IChainInfo { | ||
name: TChain; | ||
network: string; | ||
nodeRPC: string; | ||
blockExplorer: string; | ||
chainId: number; | ||
mintContractAddress: string; | ||
currency: string; | ||
} | ||
|
||
export type TSupportedChains = Record<TChain, IChainInfo>; | ||
|
||
export type TNetworks = Record<"testnet" | "mainnet", TSupportedChains>; |