From c29435f2796e672563da8efb83d669c50148fd8d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Jun 2024 16:20:19 +0000 Subject: [PATCH 1/3] added example for fee bump --- .../fee-bump-transactions.mdx | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx b/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx index d3e4ff2db..2bca72b34 100644 --- a/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx +++ b/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx @@ -60,3 +60,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 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. + + + +```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); + }); +``` + + From d5f098b6d70e616b183c157248f0c8215e6d1cb1 Mon Sep 17 00:00:00 2001 From: Bri <92327786+briwylde08@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:28:26 -0600 Subject: [PATCH 2/3] capitalization consistency --- .../transactions-specialized/fee-bump-transactions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx b/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx index 2bca72b34..c6d6b88af 100644 --- a/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx +++ b/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx @@ -61,7 +61,7 @@ The sole purpose of a fee-bump transaction is to get an inner transaction includ 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 Fee-Bump Transaction +## 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. From 7350ff6b38f30a1f590fd7950304c24fce83e2ed Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Jun 2024 07:34:53 +0000 Subject: [PATCH 3/3] Add CodeExample Import --- .../transactions-specialized/fee-bump-transactions.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx b/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx index c6d6b88af..1db55ff21 100644 --- a/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx +++ b/docs/learn/encyclopedia/transactions-specialized/fee-bump-transactions.mdx @@ -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: