Skip to content

Commit

Permalink
Resolves Docs Bounty Issue 335 (#700)
Browse files Browse the repository at this point in the history
* added example for fee bump

* capitalization consistency

* Add CodeExample Import

---------

Co-authored-by: Bri <[email protected]>
  • Loading branch information
rahul-soshte and briwylde08 authored Jun 21, 2024
1 parent cd5b5a0 commit d479ae5
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Fee-Bump Transactions
sidebar_position: 40
---

import { CodeExample } from "@site/src/components/CodeExample";

Fee-bump transactions were introduced in [CAP-0015](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0015.md) and enable an account to pay the transaction fees for an existing transaction without having to re-sign the transaction or manage sequence numbers.

A fee-bump transaction is made of two parts:
Expand Down Expand Up @@ -60,3 +62,68 @@ A fee-bump transaction goes through a series of checks in its lifecycle to deter
The sole purpose of a fee-bump transaction is to get an inner transaction included in a transaction set. Since the fee-bump transaction has no side effects other than paying a fee — and at the time the fee is paid the outer transaction must have been valid (otherwise nodes would not have voted for it) — there is no reason to check the validity of the fee-bump transaction at apply time. Therefore, the sequence number of the inner transaction is always consumed at apply time. The inner transaction, however, will still have its validity checked at apply time.

Every fee-bump transaction result contains a complete inner transaction result. This inner-transaction result is exactly what would have been produced had there been no fee-bump transaction, except that the inner fee will always be 0.

## Example: implementing a fee-bump transaction

This example shows how to create and submit a fee-bump transaction on the Stellar network. Replace secret key values, `SECREY_KEY_1` and `SECREY_KEY_2` of keypairs of your choosing. This is not a production example, and you should take care to never expose your secret keys on the web.

<CodeExample>

```js
import * as StellarSDK from "@stellar/stellar-sdk";

// Define the network passphrase (use 'Testnet' for testing and 'Public Global Stellar Network ; September 2015' for production)
const networkPassphrase = StellarSDK.Networks.TESTNET;

// Create keypairs for the source account and the fee account
const sourceKeypair = StellarSDK.Keypair.fromSecret("SECREY_KEY_1");
const feeKeypair = StellarSDK.Keypair.fromSecret("SECREY_KEY_2");

// Load the source account (this requires network interaction)
const server = new StellarSDK.Horizon.Server(
"https://horizon-testnet.stellar.org",
);
const sourceAccount = await server.loadAccount(sourceKeypair.publicKey());

// Construct the inner transaction, just a example tx, to transfer 10 XLM to a destination account
const innerTransaction = new StellarSDK.TransactionBuilder(sourceAccount, {
fee: StellarSDK.BASE_FEE,
networkPassphrase,
})
.addOperation(
StellarSDK.Operation.payment({
destination: "GDWH3P3MNTCMOY42CA7RVEACUUAUPZ73XDYKPYUL3TWOFRF37FD6OVM6",
asset: StellarSDK.Asset.native(),
amount: "10",
}),
)
.setTimeout(30)
.build();

// Sign the inner transaction with the source account
innerTransaction.sign(sourceKeypair);

// Build the fee-bump transaction
const feeBumpTransaction =
StellarSDK.TransactionBuilder.buildFeeBumpTransaction(
feeKeypair,
StellarSDK.BASE_FEE * 2,
innerTransaction,
networkPassphrase,
);

// Sign the fee-bump transaction with the fee account
feeBumpTransaction.sign(feeKeypair);

// Submit the fee-bump transaction to the Stellar network
server
.submitTransaction(feeBumpTransaction)
.then((response) => {
console.log("Success! Results:", response);
})
.catch((error) => {
console.error("Something went wrong!", error);
});
```

</CodeExample>

0 comments on commit d479ae5

Please sign in to comment.