Skip to content

Commit

Permalink
fix: resolves #2767
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Sep 25, 2024
1 parent 5b22f60 commit aadeada
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-pants-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Added default `timeout` to `waitForTransactionReceipt`.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const transaction = await publicClient.waitForTransactionReceipt(
### timeout (optional)

- **Type:** `number`
- **Default:** `180_000`

Optional timeout (in milliseconds) to wait before stopping polling.

Expand Down
16 changes: 5 additions & 11 deletions src/actions/public/waitForTransactionReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export type WaitForTransactionReceiptParameters<
* @default `({ count }) => ~~(1 << count) * 200` (exponential backoff)
*/
retryDelay?: WithRetryParameters['delay'] | undefined
/** Optional timeout (in milliseconds) to wait before stopping polling. */
/**
* Optional timeout (in milliseconds) to wait before stopping polling.
* @default 180_000
*/
timeout?: number | undefined
}

Expand Down Expand Up @@ -136,12 +139,11 @@ export async function waitForTransactionReceipt<
pollingInterval = client.pollingInterval,
retryCount = 6,
retryDelay = ({ count }) => ~~(1 << count) * 200, // exponential backoff
timeout,
timeout = 180_000,
}: WaitForTransactionReceiptParameters<chain>,
): Promise<WaitForTransactionReceiptReturnType<chain>> {
const observerId = stringify(['waitForTransactionReceipt', client.uid, hash])

let count = 0
let transaction: GetTransactionReturnType<chain> | undefined
let replacedTransaction: GetTransactionReturnType<chain> | undefined
let receipt: GetTransactionReceiptReturnType<chain>
Expand Down Expand Up @@ -177,12 +179,6 @@ export async function waitForTransactionReceipt<
let blockNumber = blockNumber_

if (retrying) return
if (count > retryCount)
done(() =>
emit.reject(
new WaitForTransactionReceiptTimeoutError({ hash }),
),
)

try {
// If we already have a valid receipt, let's check if we have enough
Expand Down Expand Up @@ -332,8 +328,6 @@ export async function waitForTransactionReceipt<
} else {
done(() => emit.reject(err))
}
} finally {
count++
}
},
})
Expand Down

0 comments on commit aadeada

Please sign in to comment.