From 33f0926a93b61b88c458e185543b91d3f80a127a Mon Sep 17 00:00:00 2001 From: Bri <92327786+briwylde08@users.noreply.github.com> Date: Tue, 30 Aug 2022 09:59:58 -0600 Subject: [PATCH] Added code blocks --- docs/encyclopedia/channel-accounts.mdx | 57 +++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/encyclopedia/channel-accounts.mdx b/docs/encyclopedia/channel-accounts.mdx index 1b26c555c..c7c419780 100644 --- a/docs/encyclopedia/channel-accounts.mdx +++ b/docs/encyclopedia/channel-accounts.mdx @@ -2,6 +2,8 @@ title: Channel Accounts --- +import { CodeExample } from "@site/src/components/CodeExample"; + Channel accounts provide a method for submitting transactions to the network at a high rate. An account’s transactions always need to be submitted to the network in increments of one sequence number (unless minimum sequence number preconditions are set). This can cause problems if you are submitting transactions at a high rate, as they can potentially reach Stellar Core out of order and will then bounce with a bad sequence error. @@ -14,4 +16,57 @@ You will, of course, have to sign the transaction with both the base account key For example: -[insert code] + + +```js +StellarSdk.Network.useTestNetwork(); +// channelAccounts[] is an array of accountIDs, one for each channel +// channelKeys[] is an array of secret keys, one for each channel +// channelIndex is the channel you want to send this transaction over + +// create payment from baseAccount to customerAddress +var transaction = new StellarSdk.TransactionBuilder( + channelAccounts[channelIndex], +) + .addOperation( + StellarSdk.Operation.payment({ + source: baseAccount.address(), + destination: customerAddress, + asset: StellarSdk.Asset.native(), + amount: amountToSend, + }), + ) + // Wait a maximum of three minutes for the transaction + .setTimeout(180) + .build(); + +transaction.sign(baseAccountKey); // base account must sign to approve the payment +transaction.sign(channelKeys[channelIndex]); // channel must sign to approve it being the source of the transaction +``` + +```python +# channelAccounts[] is an array of accountIDs, one for each channel +# channelKeys[] is an array of secret keys, one for each channel +# channelIndex is the channel you want to send this transaction over + +transaction = ( + TransactionBuilder( + source_account=channelAccounts[channelIndex], + network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, + base_fee=base_fee, + ) + .append_payment_op( + source=baseAccount.public_key, + destination=customerAddress, + asset=Asset.native(), + amount=amountToSend, + ) + .set_timeout(180) # Wait a maximum of three minutes for the transaction + .build() +) + +transaction.sign(baseAccountKey) # base account must sign to approve the payment +transaction.sign(channelKeys[channelIndex]) # channel must sign to approve it being the source of the transaction +``` + +