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