Overview
When you send a transaction using Privy, we broadcast it to the specified blockchain. However, in periods of high network congestion, the transaction may take longer than expected to be confirmed, or occasionally even never make it to confirmation. This is due to transaction fee (“gas”) estimates becoming outdated as high blockchain activity puts upward pressure on fees. In order to increase the likelihood of your transaction being confirmed, you can send a transaction that replaces the original one and sets higher gas fees. This guide will show you how to use the webhooks feature to know when a transaction is taking longer than expected, and trigger a replacement transaction to speed up confirmation.Prerequisites
- A Privy EVM wallet
- Webhooks enabled for your app
Step 1: Set up webhooks for transaction.still_pending
To start, follow the setup instructions for Webhooks From the dropdown menu, select the transaction.still_pending
event.
Step 2: Implement the webhook handler
When a transaction is taking longer than expected, Privy will emit a webhook to the destination URL you provided. Here is an example of the webhook payload:Step 3: Trigger a replacement transaction
Once you receive the webhook, you can trigger a replacement transaction by submitting a new transaction with the same nonce as the still pending transaction. If you leave out the gas fields, Privy will automatically set them based on the current network conditions. Below is an example of sending a replacement transaction using Privy’s Node SDK. For other ways to send a transaction, see the guide.Although you are sending a new transaction, there is no risk of both transactions getting
executed (unintentionally) if the nonce is set to be the same in each. On EVM chains, the nonce
is an internal counter that is incremented for each transaction sent by a wallet to avoid replay
and other attack vectors.
max_priority_fee_per_gas
to be a higher value than the original transaction.
[Optional] Step 4: Monitor the status of the replacement via webhooks
Subscribe totransaction.replaced
, transaction.failed
, and transaction.confirmed
webhooks to get notified on the success of the speedup.
Once the replacement succeeds, the following webhooks will trigger:
transaction.replaced
for the original transaction IDtransaction.confirmed
for the speedup transaction
transaction.failed
webhook would trigger.
For more information on transaction webhooks, see the correspondent docs.