Fee-Bump: How to pay for other people's transactions
Last updated
Last updated
In the blockchain and decentralized finance world, Stellar provides robust features that make it easier for developers to work with. One of these features, Fee-Bump Transactions, allows for more flexibility when dealing with transaction fees on the network. In this article, weโll explore the concept of Fee-Bump Transactions, their use cases, and how you can implement them in your application.
Fee-Bump Transactions allow one account to pay for the fees of a transaction initiated by another account. The unique aspect is that the original transaction does not need to be re-signed by the Source Account; the Fee Account can bump up the fees and pay for them, ensuring that the transaction is processed on time. This is especially helpful when the initial fee is too low, or the fee structure changes after the transaction has been created.
Imagine youโre building an app where every new user needs a Stellar wallet to interact with the network. When you create the wallet, you need to fund it with some XLM so that it can perform transactions. However, instead of having the user cover the fees, you can use Fee-Bump Transactions to make sure the fees are covered by another account, streamlining the onboarding process.
Sometimes, when you submit a transaction, the network fee might increase due to network congestion or other factors. With Fee-Bump Transactions, you can increase the fee for an existing transaction without having to re-sign the original one. This means that the transaction has a higher chance of being processed and included in the ledger.
A preauthorized transaction is similar to a post-dated check. One party (say, PersonA) authorizes another (say, PersonB) to claim a specific amount at a later time. If the fee for that transaction has increased after it was preauthorized, Fee-Bump Transactions can be used to ensure the transaction is properly processed.
To implement a Fee-Bump Transaction, there are a few simple steps to follow. You need three key accounts:
- Source Account This is the account from which the transaction originates.
- Destination Account: The recipient of the funds.
- Fee Account: This account will cover the transaction fees.
Once you have these accounts set up, you can use the Stellar SDK to construct the transaction and apply the Fee-Bump.
To demonstrate how to implement Fee-Bump Transactions, letโs walk through a simple example using the JavaScript Stellar SDK.
Make sure you have the Stellar SDK installed in your project:
or
We will create three accounts:
1. Source Account: The account sending the payment.
2. Destination Account: The account receiving the funds.
3. Fee Account: The account paying the transaction fees.
You can create them manually using the Stellar Laboratory or dinamically with the Stellar SDK
Next, weโll build the payment transaction, which will transfer XLM from the Source Account to the Destination Account.
Once the transaction is submitted, hereโs what you can expect:
- Source Account: The 200 XLM (or the amount was sent) will be deducted from the source account.
- Destination Account: The full payment amount received in the destination account (200 XLM).
- Fee Account: The fee for the transaction (e.g., 200 stroops) will be deducted from the Fee Account, ensuring that the source account doesnโt have to cover it.
You can check the transactions on the Stellar network using the Stellar Laboratory to verify that everything went through as expected.
Fee-Bump Transactions are a powerful feature in Stellar that allow developers to manage transaction fees efficiently. Whether you're creating new wallets for users, adjusting fees on existing transactions, or handling preauthorized transactions, Fee-Bump Transactions give you the flexibility to cover fees without re-signing the original transaction.
Resources: