@@ -100,6 +100,7 @@ export default class Client {
100100 #anvilInfo: AnvilNodeInfo | null = null ;
101101
102102 #publicClient?: PublicClient ;
103+ #logsClient?: PublicClient ;
103104
104105 #walletClient?: WalletClient < Transport , Chain , PrivateKeyAccount , undefined > ;
105106
@@ -113,15 +114,7 @@ export default class Client {
113114 > ;
114115
115116 public async launch ( ) : Promise < void > {
116- const { ethProviderRpcs, chainId, network, optimistic, privateKey } =
117- this . config ;
118- const rpcs = ethProviderRpcs . map ( url =>
119- http ( url , {
120- timeout : optimistic ? 240_000 : 10_000 ,
121- retryCount : optimistic ? 3 : undefined ,
122- } ) ,
123- ) ;
124- const transport = rpcs . length > 1 && ! optimistic ? fallback ( rpcs ) : rpcs [ 0 ] ;
117+ const { chainId, network, optimistic, privateKey } = this . config ;
125118 const chain = defineChain ( {
126119 ...CHAINS [ network ] ,
127120 id : chainId ,
@@ -130,13 +123,19 @@ export default class Client {
130123 this . #publicClient = createPublicClient ( {
131124 cacheTime : 0 ,
132125 chain,
133- transport,
126+ transport : this . #createTransport( ) ,
127+ pollingInterval : optimistic ? 25 : undefined ,
128+ } ) ;
129+ this . #logsClient = createPublicClient ( {
130+ cacheTime : 0 ,
131+ chain,
132+ transport : this . #createTransport( true ) ,
134133 pollingInterval : optimistic ? 25 : undefined ,
135134 } ) ;
136135 this . #walletClient = createWalletClient ( {
137136 account : privateKeyToAccount ( privateKey ) ,
138137 chain,
139- transport,
138+ transport : this . #createTransport ( ) ,
140139 pollingInterval : optimistic ? 25 : undefined ,
141140 } ) ;
142141 try {
@@ -148,7 +147,7 @@ export default class Client {
148147 AnvilRPCSchema
149148 > ( {
150149 mode : "anvil" ,
151- transport,
150+ transport : this . #createTransport ( ) ,
152151 chain,
153152 pollingInterval : 25 ,
154153 } ) ;
@@ -310,6 +309,13 @@ export default class Client {
310309 return this . #publicClient;
311310 }
312311
312+ public get logs ( ) : PublicClient {
313+ if ( ! this . #logsClient) {
314+ throw new Error ( "logs client not initialized" ) ;
315+ }
316+ return this . #logsClient;
317+ }
318+
313319 public get wallet ( ) : WalletClient <
314320 Transport ,
315321 Chain ,
@@ -354,4 +360,16 @@ export default class Client {
354360 }
355361 return BigInt ( n ) ;
356362 }
363+
364+ #createTransport( batch = false ) : Transport {
365+ const { ethProviderRpcs, optimistic } = this . config ;
366+ const rpcs = ethProviderRpcs . map ( url =>
367+ http ( url , {
368+ timeout : optimistic ? 240_000 : 10_000 ,
369+ retryCount : optimistic ? 3 : undefined ,
370+ batch,
371+ } ) ,
372+ ) ;
373+ return rpcs . length > 1 && ! optimistic ? fallback ( rpcs ) : rpcs [ 0 ] ;
374+ }
357375}
0 commit comments