Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves Docs Bounty Issue 335 #700

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading