You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the `useDropAndReplaceUserOperation()` hook to drop and replace. Retry a transaction by:
10
12
11
-
If fees change and your user operation gets stuck in the mempool, you can use drop and replace to resend the user operation with higher fees.
13
+
1. Call `sendUserOperationAsync()` from `useSendUserOperation()` to send the initial transaction; it returns the pending hash
14
+
2. Use the `useWaitForUserOperationTransaction()` hook to wait for the pending transaction
15
+
3. If the transaction is stuck in the mempool, use the `useDropAndReplaceUserOperation()` hook to cancel the existing attempt and resubmit with an adjusted fee
12
16
13
-
Here's a quick example of how to use the `useDropAndReplaceUserOperation()` hook to drop and replace a user operation.
17
+
The example below implements this flow and wraps it in a retry helper with a configurable number of attempts.
14
18
15
19
```tsx twoslash
16
20
importReactfrom"react";
17
21
import { View, Pressable, Text } from"react-native";
18
22
import {
23
+
useWaitForUserOperationTransaction,
19
24
useDropAndReplaceUserOperation,
20
25
useSendUserOperation,
21
26
useSmartAccountClient,
22
27
} from"@account-kit/react-native";
23
28
29
+
// Configure how many drop-and-replace attempts to try if timeouts persist
1. Send the initial transaction with `sendUserOperation()`; it returns the pending hash
136
+
2. Wait for the pending transaction with `waitForUserOperationTransaction({ hash })`
137
+
3. If `waitForUserOperationTransaction({ hash })` errors, drop and replace with `dropAndReplaceUserOperation()`
110
138
111
-
<Markdownsrc="../../shared/infra/client.mdx" />
139
+
The example then wraps this flow in a retry helper with a configurable number of attempts.
112
140
113
-
</CodeBlocks>
141
+
```ts twoslash
142
+
import { client } from"./client";
114
143
115
-
In the above example, we only try to drop and replace once before failing completely, but you can build more complex retry logic using this combination of `waitForUserOperationTransaction` and `dropAndReplace`.
In the previous guides, we learned how to send user operations with gas sponsorship, but what happens when a user operation fails to mine? In this guide,
2
-
we'll cover how to use drop and replace to resend failing user operations and ensure they get mined.
1
+
Network fees can change quickly. When fees rise, pending transactions may become underpriced and stop progressing. Without retries, these transactions may never confirm. Use retries to keep your app reliable.
3
2
4
-
## What is drop and replace?
3
+
**Why retries matter**
5
4
6
-
If fees change and your user operation gets stuck in the mempool, you can use drop and replace to resend the user operation with higher fees. This is most useful
7
-
when used in combination with [`waitForUserOperationTransaction`](/wallets/reference/aa-sdk/core/functions/waitForUserOperationTransaction) to ensure the transaction is mined
8
-
and then resend the user operation with higher fees if waiting times out.
5
+
-**Production reliability**: Proper wait and retry mechanisms ensure transactions don’t get stuck and fail silently.
6
+
-**Fee volatility**: Gas markets fluctuate constantly, especially on testnets, so transactions can become underpriced and take much longer to mine.
7
+
-**Automatic recovery**: Retries automatically replace stuck transactions with higher fees so they continue to progress.
9
8
10
-
Drop and replace works by resubmitting a user operation with the greater of:
9
+
## How it works
11
10
12
-
1. 10% higher fees
13
-
2. The current minimum fees
11
+
Drop and replace resubmits a transaction with whichever is greater:
14
12
15
-
We export a `dropAndReplace` function from `@aa-sdk/core` that you can use to handle this flow for you and is automatically added to the Smart Account Client.
13
+
- 10% higher fees
14
+
- The current minimum fees
16
15
17
-
## How to drop and replace effectively
16
+
The SDK exports a `dropAndReplace` function from `@aa-sdk/core`. It is available on the `Smart Account Client`, so use it directly.
18
17
19
-
Let's run through an example that uses drop and replace if waiting for a user operation to mine times out.
18
+
Here’s a common production flow:
19
+
20
+
1. Send a transaction with `sendUserOperation`
21
+
2. Wait for confirmation using `waitForUserOperationTransaction`
22
+
3. If waiting times out, call `dropAndReplace` to resend the transaction with higher fees
20
23
21
24
<Warning>
22
-
If sponsoring gas, like in the example below, each call to `sendUserOperation`
23
-
and `dropAndReplace` will generate pending gas sponsorships in your dashboard.
24
-
This can result in you hitting your gas manager limit. At the moment, pending
25
-
sponsorships expire after 10 minutes of inactivity, but it is possible that
26
-
retrying excessively can temporarily exhaust your sponsorship limits.
25
+
If you sponsor gas, each retry creates a pending gas sponsorship in your
26
+
dashboard. Pending sponsorships expire after 10 minutes of inactivity.
27
+
Excessive retries can temporarily exhaust your sponsorship limit.
0 commit comments