@@ -20,6 +20,7 @@ import {
2020import type { PreparedTransaction } from "../../transaction/prepare-transaction.js" ;
2121import { getAddress } from "../../utils/address.js" ;
2222import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js" ;
23+ import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js" ;
2324import { concatHex } from "../../utils/encoding/helpers/concat-hex.js" ;
2425import type { Hex } from "../../utils/encoding/hex.js" ;
2526import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js" ;
@@ -256,6 +257,11 @@ async function createSmartAccount(
256257 account,
257258 accountContract,
258259 } ) ;
260+ // the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
261+ // the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
262+ await confirmContractDeployment ( {
263+ accountContract,
264+ } ) ;
259265 }
260266
261267 const originalMsgHash = hashMessage ( message ) ;
@@ -344,6 +350,11 @@ async function createSmartAccount(
344350 account,
345351 accountContract,
346352 } ) ;
353+ // the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
354+ // the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
355+ await confirmContractDeployment ( {
356+ accountContract,
357+ } ) ;
347358 }
348359
349360 const originalMsgHash = hashTypedData ( typedData ) ;
@@ -607,3 +618,21 @@ async function _sendUserOp(args: {
607618 transactionHash : receipt . transactionHash ,
608619 } ;
609620}
621+
622+ async function confirmContractDeployment ( args : {
623+ accountContract : ThirdwebContract ;
624+ } ) {
625+ const { accountContract } = args ;
626+ const startTime = Date . now ( ) ;
627+ const timeout = 60000 ; // wait 1 minute max
628+ let isDeployed = await isContractDeployed ( accountContract ) ;
629+ while ( ! isDeployed ) {
630+ if ( Date . now ( ) - startTime > timeout ) {
631+ throw new Error (
632+ "Timeout: Smart account deployment not confirmed after 1 minute" ,
633+ ) ;
634+ }
635+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
636+ isDeployed = await isContractDeployed ( accountContract ) ;
637+ }
638+ }
0 commit comments