@@ -47,9 +47,17 @@ export const chains: Record<string, Chain> = {
4747 [ optimism . id . toString ( ) ] : optimism ,
4848} ;
4949
50+ export const chainInAlchemy : Record < string , string > = {
51+ [ mainnet . id . toString ( ) ] : 'eth-mainnet' ,
52+ [ arbitrum . id . toString ( ) ] : 'arb-mainnet' ,
53+ [ avalanche . id . toString ( ) ] : 'avax-mainnet' ,
54+ [ base . id . toString ( ) ] : 'base-mainnet' ,
55+ [ optimism . id . toString ( ) ] : 'opt-mainnet' ,
56+ } ;
57+
5058export const publicClients = Object . keys ( chains ) . reduce ( ( acc , chainId ) => {
5159 acc [ chainId ] = createPublicClient ( {
52- transport : http ( getRPCEndpoint ( chainId ) ) ,
60+ transport : http ( getAlchemyRPCEndpoint ( chainId ) ) ,
5361 chain : chains [ chainId ] ,
5462 } ) ;
5563 return acc ;
@@ -216,7 +224,7 @@ async function registerAddressWithAlchemyWebhookWithRetry(
216224 */
217225export async function getSmartAccountAddress ( address : string ) : Promise < string > {
218226 const publicAvalancheClient = createPublicClient ( {
219- transport : http ( getRPCEndpoint ( avalanche . id . toString ( ) ) ) ,
227+ transport : http ( getAlchemyRPCEndpoint ( avalanche . id . toString ( ) ) ) ,
220228 chain : avalanche ,
221229 } ) ;
222230
@@ -265,13 +273,20 @@ export function isSupportedEVMChainId(chainId: string): boolean {
265273 return Object . keys ( chains ) . includes ( chainId ) ;
266274}
267275
268- export function getRPCEndpoint ( chainId : string ) : string {
276+ export function getZeroDevRPCEndpoint ( chainId : string ) : string {
269277 if ( ! isSupportedEVMChainId ( chainId ) ) {
270278 throw new Error ( `Unsupported chainId: ${ chainId } ` ) ;
271279 }
272280 return `${ config . ZERODEV_API_BASE_URL } /${ config . ZERODEV_API_KEY } /chain/${ chainId } ` ;
273281}
274282
283+ export function getAlchemyRPCEndpoint ( chainId : string ) : string {
284+ if ( ! isSupportedEVMChainId ( chainId ) ) {
285+ throw new Error ( `Unsupported chainId: ${ chainId } ` ) ;
286+ }
287+ return `https://${ chainInAlchemy [ chainId ] } .g.alchemy.com/v2/${ config . ALCHEMY_API_KEY } ` ;
288+ }
289+
275290// TODO: Verify that this function is 1000% correct. @RUI and @TYLER and @JARED
276291export function getAddress (
277292 chainId : string ,
0 commit comments