Skip to content

Commit

Permalink
use alchemy and infura provider
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKurt authored and thelostone-mc committed Jun 10, 2024
1 parent ed764a8 commit 841be6d
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion packages/common/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@ import { getChains, TChain } from "@gitcoin/gitcoin-chain-data";

const chainData = getChains();

const rpcUrls: { [key: number]: string | undefined } = {
1: "https://eth-mainnet.g.alchemy.com/v2/",
10: "https://opt-mainnet.g.alchemy.com/v2/",
// 42: "", // lukso
137: "https://polygon-mainnet.g.alchemy.com/v2/",
// 250: "", // fantom
300: "https://zksync-sepolia.g.alchemy.com/v2/",
324: "https://zksync-mainnet.g.alchemy.com/v2/",
// 4201: "", // lukso test
8453: "https://base-mainnet.g.alchemy.com/v2/",
42161: "https://arb-mainnet.g.alchemy.com/v2/",
42220: "https://celo-mainnet.infura.io/v3/", // celo
43113: "https://avalanche-fuji.infura.io/v3/", // fuji
43114: "https://avalanche-mainnet.infura.io/v3/", // avax
44787: "https://celo-alfajores.infura.io/v3/", // alfajores
// 80001: "https://polygon-mumbai.g.alchemy.com/v2/", // not supported anymore
// 534351: "", // scroll sepol
// 534352: "", // scroll mainnet
// 1329: "", // sei
// 713715: "", // sei devnet
11155111: "https://eth-sepolia.g.alchemy.com/v2/",
};

const getRpcUrl = (chain: TChain): string => {
let envRpc = rpcUrls[chain.id] ?? chain.rpc;

if (envRpc.includes("alchemy"))
envRpc = process.env.REACT_APP_ALCHEMY_ID
? envRpc + process.env.REACT_APP_ALCHEMY_ID
: chain.rpc;
if (envRpc.includes("infura"))
envRpc = process.env.REACT_APP_INFURA_ID
? envRpc + process.env.REACT_APP_INFURA_ID
: chain.rpc;

return envRpc;
};
export function stringToBlobUrl(data: string): string {
const blob = new Blob([data], { type: "image/svg+xml" });
const url = URL.createObjectURL(blob);
Expand All @@ -15,6 +52,8 @@ const parseRainbowChain = (chain: TChain) => {
(token) => token.address === zeroAddress
);

const rpc = getRpcUrl(chain);

// Map the TChain to @rainbow-me/rainbowkit/Chain
const mappedChain = {
id: chain.id,
Expand All @@ -29,7 +68,7 @@ const parseRainbowChain = (chain: TChain) => {
},
rpcUrls: {
default: {
http: [chain.rpc],
http: [rpc],
webSocket: undefined,
},
public: {
Expand Down

0 comments on commit 841be6d

Please sign in to comment.