@@ -256,6 +256,11 @@ async function createSmartAccount(
256
256
account,
257
257
accountContract,
258
258
} ) ;
259
+ // the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
260
+ // the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
261
+ await confirmContractDeployment ( {
262
+ accountContract,
263
+ } ) ;
259
264
}
260
265
261
266
const originalMsgHash = hashMessage ( message ) ;
@@ -344,6 +349,11 @@ async function createSmartAccount(
344
349
account,
345
350
accountContract,
346
351
} ) ;
352
+ // the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
353
+ // the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
354
+ await confirmContractDeployment ( {
355
+ accountContract,
356
+ } ) ;
347
357
}
348
358
349
359
const originalMsgHash = hashTypedData ( typedData ) ;
@@ -607,3 +617,24 @@ async function _sendUserOp(args: {
607
617
transactionHash : receipt . transactionHash ,
608
618
} ;
609
619
}
620
+
621
+ async function confirmContractDeployment ( args : {
622
+ accountContract : ThirdwebContract ;
623
+ } ) {
624
+ const { accountContract } = args ;
625
+ const startTime = Date . now ( ) ;
626
+ const timeout = 60000 ; // wait 1 minute max
627
+ const { isContractDeployed } = await import (
628
+ "../../utils/bytecode/is-contract-deployed.js"
629
+ ) ;
630
+ let isDeployed = await isContractDeployed ( accountContract ) ;
631
+ while ( ! isDeployed ) {
632
+ if ( Date . now ( ) - startTime > timeout ) {
633
+ throw new Error (
634
+ "Timeout: Smart account deployment not confirmed after 1 minute" ,
635
+ ) ;
636
+ }
637
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
638
+ isDeployed = await isContractDeployed ( accountContract ) ;
639
+ }
640
+ }
0 commit comments