File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,17 +110,34 @@ export async function estimateDeploymentCost(
110110}
111111
112112/**
113- * Verify contract deployment
113+ * Verify contract deployment with retry logic for public RPCs.
114+ *
115+ * Public RPC endpoints may return stale data immediately after a transaction
116+ * is mined, causing `getCode()` to return `'0x'` even though the contract was
117+ * deployed successfully. We retry a few times with exponential back-off
118+ * before giving up.
114119 */
115120export async function verifyDeployment (
116121 hre : HardhatRuntimeEnvironment ,
117122 contractAddress : string ,
118123 quiet : boolean = false
119124) {
120- // Verify that contract was deployed successfully
121- const code = await hre . ethers . provider . getCode ( contractAddress ) ;
122- if ( code === '0x' ) {
123- throw new Error ( 'Contract deployment failed - no code at address' ) ;
125+ const maxRetries = 5 ;
126+ const baseDelayMs = 2000 ;
127+
128+ for ( let attempt = 1 ; attempt <= maxRetries ; attempt ++ ) {
129+ const code = await hre . ethers . provider . getCode ( contractAddress ) ;
130+ if ( code !== '0x' ) {
131+ break ;
132+ }
133+ if ( attempt === maxRetries ) {
134+ throw new Error ( 'Contract deployment failed - no code at address after ' + maxRetries + ' attempts' ) ;
135+ }
136+ const delay = baseDelayMs * attempt ;
137+ if ( ! quiet ) {
138+ console . log ( `Waiting for contract code at ${ contractAddress } (attempt ${ attempt } /${ maxRetries } , next retry in ${ delay } ms)...` ) ;
139+ }
140+ await new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
124141 }
125142
126143 // Get implementation contract address
You can’t perform that action at this time.
0 commit comments