Channel accounts
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.
To avoid this, you can create separate channel accounts that can be used as the source account for the transaction and use the account holding the assets as the base account or the source account for the individual operations in the transaction. In this scenario, the assets will come out of the base account, and the sequence number and fees will be consumed by the channel account.
Channels take advantage of the fact that the source account of a transaction can be different than the source account of the operations inside the transaction. With this setup, you can make as many channels as you need to maintain your desired transaction rate.
You will, of course, have to sign the transaction with both the base account key and the channel account key.
For example:
- JavaScript
- 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
// create payment from baseAccount to customerAddress
var transaction = new StellarSdk.TransactionBuilder(
channelAccounts[channelIndex],
{
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
},
)
.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
# 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
Guides in this category:
๐๏ธ Create an account
Learn about creating Stellar accounts, keypairs, funding, and account basics.
๐๏ธ Send and receive payments
Learn to send payments and watch for received payments on the Stellar network.
๐๏ธ Channel accounts
Create channel accounts to submit transactions to the network at a high rate.
๐๏ธ Claimable balances
Split a payment into two parts by creating a claimable balance.
๐๏ธ Clawbacks
Use clawbacks to burn a specific amount of a clawback-enabled asset from a trustline or claimable balance.
๐๏ธ Fee-bump transactions
Use fee-bump transactions to pay for transaction fees on behalf of another account without re-signing the transaction.
๐๏ธ Sponsored reserves
Use sponsored reserves to pay for base reserves on behalf of another account.
๐๏ธ Path payments
Send a payment where the asset received differs from the asset sent.
๐๏ธ Pooled accounts: muxed accounts and memos
Use muxed accounts to differentiate between individual accounts in a pooled account.
๐๏ธ Install and deploy a smart contract with code
Install and deploy a smart contract with code.
๐๏ธ Install WebAssembly (Wasm) bytecode using code
Install the Wasm of the contract using js-stellar-sdk.
๐๏ธ Invoke a contract function in a Stellar transaction using SDKs
Use the Stellar SDK to create, simulate, and assemble a transaction.
๐๏ธ simulateTransaction RPC method guide
simulateTransaction examples and tutorials guide.
๐๏ธ Submit a transaction to Stellar RPC using the JavaScript SDK
Use a looping mechanism to submit a transaction to the RPC.