@@ -3,26 +3,38 @@ import React from "react";
33import { createWeb3Modal } from "@web3modal/wagmi/react" ;
44import { type Chain } from "viem" ;
55import { createConfig , fallback , http , WagmiProvider , webSocket } from "wagmi" ;
6- import { mainnet , arbitrumSepolia } from "wagmi/chains" ;
6+ import { mainnet , arbitrumSepolia , arbitrum , gnosisChiado , sepolia , gnosis } from "wagmi/chains" ;
77import { walletConnect } from "wagmi/connectors" ;
88
99import { ALL_CHAINS } from "consts/chains" ;
1010
1111import { theme } from "styles/Theme" ;
1212
13- const alchemyApiKey = process . env . NEXT_PUBLIC_ALCHEMY_API_KEY ?? "" ;
13+ const alchemyApiKey = process . env . NEXT_PUBLIC_ALCHEMY_API_KEY ;
14+ if ( ! alchemyApiKey ) {
15+ throw new Error ( "Alchemy API key is not set in NEXT_PUBLIC_ALCHEMY_API_KEY environment variable." ) ;
16+ }
1417
15- // https://github.com/alchemyplatform/alchemy-sdk-js/blob/96b3f62 /src/types/types.ts#L98-L119
16- const alchemyToViemChain = {
18+ // https://github.com/alchemyplatform/alchemy-sdk-js/blob/c4440cb /src/types/types.ts#L98-L153
19+ const alchemyToViemChain : Record < number , string > = {
1720 [ arbitrumSepolia . id ] : "arb-sepolia" ,
21+ [ arbitrum . id ] : "arb-mainnet" ,
1822 [ mainnet . id ] : "eth-mainnet" ,
23+ [ sepolia . id ] : "eth-sepolia" ,
24+ [ gnosis . id ] : "gnosis-mainnet" ,
25+ [ gnosisChiado . id ] : "gnosis-chiado" ,
1926} ;
2027
2128type AlchemyProtocol = "https" | "wss" ;
2229
23- // https://github.com/alchemyplatform/alchemy-sdk-js/blob/96b3f62/src/util/const.ts#L16-L18
24- const alchemyURL = ( protocol : AlchemyProtocol , chainId : number ) =>
25- `${ protocol } ://${ alchemyToViemChain [ chainId ] } .g.alchemy.com/v2/${ alchemyApiKey } ` ;
30+ // https://github.com/alchemyplatform/alchemy-sdk-js/blob/c4440cb/src/util/const.ts#L16-L18
31+ function alchemyURL ( protocol : AlchemyProtocol , chainId : number ) : string {
32+ const network = alchemyToViemChain [ chainId ] ;
33+ if ( ! network ) {
34+ throw new Error ( `Unsupported chain ID: ${ chainId } ` ) ;
35+ }
36+ return `${ protocol } ://${ network } .g.alchemy.com/v2/${ alchemyApiKey } ` ;
37+ }
2638
2739export const getTransports = ( ) => {
2840 const alchemyTransport = ( chain : Chain ) =>
@@ -36,7 +48,12 @@ export const getTransports = () => {
3648
3749const chains = ALL_CHAINS as [ Chain , ...Chain [ ] ] ;
3850const transports = getTransports ( ) ;
39- const projectId = process . env . NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID ?? "" ;
51+
52+ const projectId = process . env . NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID ;
53+ if ( ! projectId ) {
54+ throw new Error ( "WalletConnect project ID is not set in NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID environment variable." ) ;
55+ }
56+
4057const wagmiConfig = createConfig ( {
4158 chains,
4259 transports,
0 commit comments