@@ -3,26 +3,38 @@ import React from "react";
3
3
import { createWeb3Modal } from "@web3modal/wagmi/react" ;
4
4
import { type Chain } from "viem" ;
5
5
import { 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" ;
7
7
import { walletConnect } from "wagmi/connectors" ;
8
8
9
9
import { ALL_CHAINS } from "consts/chains" ;
10
10
11
11
import { theme } from "styles/Theme" ;
12
12
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
+ }
14
17
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 > = {
17
20
[ arbitrumSepolia . id ] : "arb-sepolia" ,
21
+ [ arbitrum . id ] : "arb-mainnet" ,
18
22
[ mainnet . id ] : "eth-mainnet" ,
23
+ [ sepolia . id ] : "eth-sepolia" ,
24
+ [ gnosis . id ] : "gnosis-mainnet" ,
25
+ [ gnosisChiado . id ] : "gnosis-chiado" ,
19
26
} ;
20
27
21
28
type AlchemyProtocol = "https" | "wss" ;
22
29
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
+ }
26
38
27
39
export const getTransports = ( ) => {
28
40
const alchemyTransport = ( chain : Chain ) =>
@@ -36,7 +48,12 @@ export const getTransports = () => {
36
48
37
49
const chains = ALL_CHAINS as [ Chain , ...Chain [ ] ] ;
38
50
const 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
+
40
57
const wagmiConfig = createConfig ( {
41
58
chains,
42
59
transports,
0 commit comments