@@ -3,15 +3,15 @@ import {
33 type Address ,
44 decodeEventLog ,
55 getContract ,
6- GetContractReturnType ,
6+ type GetContractReturnType ,
77 type Hash ,
8- publicActions ,
9- PublicClient ,
10- WalletClient
8+ type PublicClient ,
9+ type WalletClient
1110} from "viem" ;
1211
1312import { IdentityCredential } from "../identity.js" ;
14- import { DecryptedCredentials } from "../keystore/types.js" ;
13+ import type { DecryptedCredentials } from "../keystore/types.js" ;
14+ import type { RpcClient } from "../utils/index.js" ;
1515
1616import {
1717 DEFAULT_RATE_LIMIT ,
@@ -32,7 +32,7 @@ export class RLNBaseContract {
3232 typeof wakuRlnV2Abi ,
3333 PublicClient | WalletClient
3434 > ;
35- public rpcClient : WalletClient & PublicClient ;
35+ public rpcClient : RpcClient ;
3636 private rateLimit : number ;
3737 private minRateLimit ?: number ;
3838 private maxRateLimit ?: number ;
@@ -45,8 +45,7 @@ export class RLNBaseContract {
4545
4646 log . info ( "Initializing RLNBaseContract" , { address, rateLimit } ) ;
4747
48- this . rpcClient = rpcClient . extend ( publicActions ) as WalletClient &
49- PublicClient ;
48+ this . rpcClient = rpcClient ;
5049 this . contract = getContract ( {
5150 address,
5251 abi : wakuRlnV2Abi ,
@@ -223,15 +222,15 @@ export class RLNBaseContract {
223222 try {
224223 await this . contract . simulate . extendMemberships ( [ [ idCommitmentBigInt ] ] , {
225224 chain : this . rpcClient . chain ,
226- account : ( this . rpcClient as WalletClient ) . account ! . address
225+ account : this . rpcClient . account . address
227226 } ) ;
228227 } catch ( err ) {
229228 throw new Error ( "Simulating extending membership failed: " + err ) ;
230229 }
231230 const hash = await this . contract . write . extendMemberships (
232231 [ [ idCommitmentBigInt ] ] ,
233232 {
234- account : this . rpcClient . account ! ,
233+ account : this . rpcClient . account ,
235234 chain : this . rpcClient . chain
236235 }
237236 ) ;
@@ -261,7 +260,7 @@ export class RLNBaseContract {
261260 [ [ idCommitmentBigInt ] , eraseFromMembershipSet ] ,
262261 {
263262 chain : this . rpcClient . chain ,
264- account : ( this . rpcClient as WalletClient ) . account ! . address
263+ account : this . rpcClient . account . address
265264 }
266265 ) ;
267266 } catch ( err ) {
@@ -272,7 +271,7 @@ export class RLNBaseContract {
272271 [ [ idCommitmentBigInt ] , eraseFromMembershipSet ] ,
273272 {
274273 chain : this . rpcClient . chain ,
275- account : this . rpcClient . account !
274+ account : this . rpcClient . account
276275 }
277276 ) ;
278277 await this . rpcClient . waitForTransactionReceipt ( { hash } ) ;
@@ -301,7 +300,7 @@ export class RLNBaseContract {
301300 [ idCommitmentBigInt , rateLimit , [ ] ] ,
302301 {
303302 chain : this . rpcClient . chain ,
304- account : ( this . rpcClient as WalletClient ) . account ! . address
303+ account : this . rpcClient . account . address
305304 }
306305 ) ;
307306 } catch ( err ) {
@@ -312,7 +311,7 @@ export class RLNBaseContract {
312311 [ idCommitmentBigInt , rateLimit , [ ] ] ,
313312 {
314313 chain : this . rpcClient . chain ,
315- account : this . rpcClient . account !
314+ account : this . rpcClient . account
316315 }
317316 ) ;
318317 await this . rpcClient . waitForTransactionReceipt ( { hash } ) ;
@@ -333,15 +332,15 @@ export class RLNBaseContract {
333332 try {
334333 await this . contract . simulate . withdraw ( [ token as Address ] , {
335334 chain : this . rpcClient . chain ,
336- account : ( this . rpcClient as WalletClient ) . account ! . address
335+ account : this . rpcClient . account . address
337336 } ) ;
338337 } catch ( err ) {
339338 throw new Error ( "Error simulating withdraw: " + err ) ;
340339 }
341340
342341 const hash = await this . contract . write . withdraw ( [ token as Address ] , {
343342 chain : this . rpcClient . chain ,
344- account : this . rpcClient . account !
343+ account : this . rpcClient . account
345344 } ) ;
346345
347346 await this . rpcClient . waitForTransactionReceipt ( { hash } ) ;
@@ -351,6 +350,12 @@ export class RLNBaseContract {
351350 identity : IdentityCredential
352351 ) : Promise < DecryptedCredentials | undefined > {
353352 try {
353+ if ( ! this . rpcClient . account ) {
354+ throw new Error (
355+ "Failed to registerWithIdentity: no account set in wallet client"
356+ ) ;
357+ }
358+
354359 log . info (
355360 `Registering identity with rate limit: ${ this . rateLimit } messages/epoch`
356361 ) ;
@@ -377,15 +382,15 @@ export class RLNBaseContract {
377382 [ identity . IDCommitmentBigInt , this . rateLimit , [ ] ] ,
378383 {
379384 chain : this . rpcClient . chain ,
380- account : ( this . rpcClient as WalletClient ) . account ! . address
385+ account : this . rpcClient . account . address
381386 }
382387 ) ;
383388
384389 const hash : Hash = await this . contract . write . register (
385390 [ identity . IDCommitmentBigInt , this . rateLimit , [ ] ] ,
386391 {
387392 chain : this . rpcClient . chain ,
388- account : this . rpcClient . account !
393+ account : this . rpcClient . account
389394 }
390395 ) ;
391396
0 commit comments