๐Ÿš€
Stellar Kickstart
  • ๐Ÿ•๏ธWelcome to the SCF Kickstart Week
    • ๐Ÿ’ฐFunding Overview
    • โœ๏ธDear changemakers, visionaries, and problem solvers
    • โ„น๏ธTL;DR: How to Maximize Your SCF Kickstart Week Experience
  • ๐Ÿ“šFundamentals of Integrating with Stellar
    • ๐Ÿš€Stellar For
    • ๐Ÿ—๏ธBuilding with Stellar
    • ๐Ÿ”งTools
    • ๐Ÿ‘ทResources
      • Fundamental Concepts
        • โญIntroduction to the Stellar network
        • โ›“๏ธIntroduction to blockchain technology
        • ๐Ÿ’ตIntroduction to payments in Stellar
        • ๐Ÿง‘Accounts
      • Core Features & Mechanisms
        • ๐Ÿ”Assets: Powering Digital Value Exchange
        • Assets Issuance: Manage digital assets effortlessly on Stellar
        • ๐Ÿ’ธTransactions: At Stellar Core
        • ๐Ÿ‘ฎโ€โ™‚๏ธSignatures in Stellar: Who, how much and to what is authorized
      • Payments & Transactions
        • ๐Ÿ’ฐPayments: Simplifying Transactions with Stellar
        • โ›“๏ธPath Payments: Convert Assets at Minimal Cost
        • โ›ฝFee-Bump: How to pay for other people's transactions
      • Developer & Integration Tools
        • ๐Ÿ‘ฉโ€๐Ÿ”ฌStellar Laboratory: Stellar at hand for everyone
        • ๐ŸšชFaucet: Easy Access to Free Blockchain Assets
        • ๐ŸงฐStellar Wallets Kit: A kit to handle all Stellar Wallets at once with a simple API
        • โœ๏ธSimple Signer: A wallet aggregator and transaction signer
      • Advanced Development & Testing
        • ๐ŸงชHow to Create Integration Tests Using GitHub Actions and Stellar's Docker Image
  • ๐ŸŽจDesign Sprint
    • ๐ŸŒ…Introduction
    • 1๏ธโƒฃDay 1 - Validate your problem and define your MVP's Scope
    • 2๏ธโƒฃDay 2 - Build a prototype to validate with real users
    • 3๏ธโƒฃDay 3 - Define the technical architecture
    • 4๏ธโƒฃDay 4: Develop your Go To Market Strategy & Pitch Deck
    • 5๏ธโƒฃDay 5: Compile all the information
    • ๐Ÿ‘€Sample Completed Design Sprint
Powered by GitBook
On this page
  • Understanding Fee-Bump Transactions in Stellar
  • What is a Fee-Bump Transaction?
  • Use Cases for Fee-Bump Transactions
  • How Does Fee-Bump Transactions Work?
  • Implementing Fee-Bump Transactions with the JavaScript Stellar SDK
  1. Fundamentals of Integrating with Stellar
  2. Resources
  3. Payments & Transactions

Fee-Bump: How to pay for other people's transactions

PreviousPath Payments: Convert Assets at Minimal CostNextDeveloper & Integration Tools

Last updated 4 months ago

Understanding Fee-Bump Transactions in Stellar

What is a Fee-Bump Transaction?

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.

Use Cases for Fee-Bump Transactions

1. Funding New Wallets for Users

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.

2. Fee Adjustment for Existing Transactions

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.

3. Preauthorized Transactions

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.

How Does Fee-Bump Transactions Work?

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.

Implementing Fee-Bump Transactions with the JavaScript Stellar SDK

Step 1: Install the Stellar SDK

Make sure you have the Stellar SDK installed in your project:

npm install --save @stellar/stellar-sdk

or

yarn add @stellar/stellar-sdk

Step 2: Define Accounts

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.

Step 3: Build the Payment Transaction

Next, weโ€™ll build the payment transaction, which will transfer XLM from the Source Account to the Destination Account.

import {
  Asset,
  BASE_FEE,
  Horizon,
  Keypair,
  Networks,
  Operation,
  TransactionBuilder,
} from "stellar-sdk";

const server = new Horizon.Server("https://horizon-testnet.stellar.org");

(async () => {
  const sourceKeypair = Keypair.fromSecret(
    "SAC4R57TC5MUT5U77WE5BB2RAM6XU5QVLQBIIY4YU3EP2SJPEDGZRQ3F"
  );
  const destinationKeypair = Keypair.fromSecret(
    "SCQ5DB7BBEXBZQVOUEID7LLILJGOVXSNH2YOJIWQYR6XMMXBM43LYVHZ"
  );
  const feeKeypair = Keypair.fromSecret(
    "SC73C2LSEHM2PPJ22E66PVCXZYIA36XISHWXIA5W5OAW2ITLB5OBR47H"
  );

  const sourceAccount = await server.loadAccount(sourceKeypair.publicKey());

  const innerTransaction = new TransactionBuilder(sourceAccount, {
    fee: BASE_FEE,
    networkPassphrase: Networks.TESTNET,
  })
    .addOperation(
      Operation.payment({
        amount: "200",
        asset: Asset.native(),
        destination: destinationKeypair.publicKey(),
      })
    )
    .setTimeout(30)
    .build();

  innerTransaction.sign(sourceKeypair);

  console.log("Inner transaction has been signed correctly");

  const feeBumpTransaction = new TransactionBuilder.buildFeeBumpTransaction(
    feeKeypair,
    BASE_FEE,
    innerTransaction,
    Networks.TESTNET
  );

  feeBumpTransaction.sign(feeKeypair);

  console.log("Fee bump transaction has been signed correctly");

  try {
    const submit = await server.submitTransaction(feeBumpTransaction);
    console.log(`Submitted transaction: ${submit.result_xdr}`);
  } catch (error) {
    console.error(error);
  }
})();

Step 4: Understanding the Results

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.

Conclusion

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:

In the blockchain and decentralized finance world, Stellar provides robust features that make it easier for developers to work with. One of these features, , 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.

Once you have these accounts set up, you can use the 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 .

You can create them manually using the or dinamically with the Stellar SDK

You can check the transactions on the Stellar network using the to verify that everything went through as expected.

-

๐Ÿ“š
๐Ÿ‘ท
โ›ฝ
Fee-Bump Transactions
Stellar SDK
JavaScript Stellar SDK
Stellar Laboratory
Stellar Laboratory
Fee Bump Example - GitHub Repository