Speeding up transactions on EVM chains
Learn how to use webhooks to trigger replacement transactions to speed up transaction confirmation.
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.
This transaction will replace the original transaction and return a new transaction hash and transaction id.
Optionally, to increase the likelihood of the replacement transaction being confirmed, you can set the max_priority_fee_per_gas
to be a higher value than the original transaction.
[Optional] Step 4: Check on the status of the replacement transaction
You can check whether the transaction is confirmed using the API or the transaction.confirmed
webhook.