Skip to content

Commit

Permalink
Add initial chains configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
eliezerbasubi committed Apr 29, 2022
1 parent 798c634 commit 6592ded
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/config/chains.ts
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;
28 changes: 28 additions & 0 deletions lib/web3/index.ts
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;
15 changes: 15 additions & 0 deletions types/chains.ts
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>;

0 comments on commit 6592ded

Please sign in to comment.