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 guide will show you how to use the webhooks feature to know when a transaction is delayed, 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.delayed
To start, follow the setup instructions for Webhooks From the dropdown menu, select the transaction.delayed
event.
Step 2: Implement the webhook handler
When a transaction is delayed, 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 delayed 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.
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.