11import {
22 WalletClient ,
33 PublicClient ,
4+ Chain ,
45 createPublicClient ,
56 http ,
67 GetBytecodeReturnType ,
@@ -75,6 +76,7 @@ declare global {
7576
7677class TokenboundClient {
7778 private chainId : number
79+ private chain : Chain
7880 public isInitialized : boolean = false
7981 public publicClient : PublicClient
8082 private supportsV3 : boolean = true // Default to V3 implementation
@@ -111,6 +113,7 @@ class TokenboundClient {
111113 }
112114
113115 this . chainId = chainId ?? chain ! . id
116+ this . chain = chain ?? chainIdToChain ( this . chainId )
114117
115118 if ( signer ) {
116119 this . signer = signer
@@ -124,7 +127,7 @@ class TokenboundClient {
124127 this . publicClient =
125128 publicClient ??
126129 createPublicClient ( {
127- chain : chain ?? chainIdToChain ( this . chainId ) ,
130+ chain : this . chain ,
128131 transport :
129132 walletClient && ! publicClientRPCUrl
130133 ? custom ( walletClient . transport )
@@ -315,7 +318,7 @@ class TokenboundClient {
315318 txHash = this . supportsV3
316319 ? await this . walletClient . sendTransaction ( {
317320 ...preparedCreateAccount ,
318- chain : chainIdToChain ( this . chainId ) ,
321+ chain : this . chain ,
319322 account : this . walletClient ?. account ?. address ! ,
320323 } ) // @BJ TODO: extract into viemV3?
321324 : await createAccount (
@@ -392,7 +395,7 @@ class TokenboundClient {
392395 return await this . walletClient . sendTransaction ( {
393396 // chain and account need to be added explicitly
394397 // because they're optional when instantiating a WalletClient
395- chain : chainIdToChain ( this . chainId ) ,
398+ chain : this . chain ,
396399 account : this . walletClient . account ! ,
397400 ...preparedExecuteCall ,
398401 } )
@@ -462,7 +465,7 @@ class TokenboundClient {
462465 return await this . walletClient . sendTransaction ( {
463466 // chain and account need to be added explicitly
464467 // because they're optional when instantiating a WalletClient
465- chain : chainIdToChain ( this . chainId ) ,
468+ chain : this . chain ,
466469 account : this . walletClient . account ! ,
467470 ...preparedExecution ,
468471 } )
@@ -519,7 +522,7 @@ class TokenboundClient {
519522 return await this . publicClient
520523 . getBytecode ( { address : accountAddress } )
521524 . then ( ( bytecode : GetBytecodeReturnType ) => {
522- return bytecode ? bytecode . length > 2 : false
525+ return ! ! bytecode ? bytecode . length > 2 : false
523526 } )
524527 } catch ( error ) {
525528 throw error
0 commit comments