Submit Multiple Operations in One Transaction¶
A Koinos transaction can contain multiple operations. They are atomic: either the transaction succeeds as a unit or its state changes are reverted. These examples build testnet-only dry-run plans.
Build a transfer batch¶
export async function buildBatch(from, transfers) {
const operations = [];
for (const transfer of transfers) {
operations.push(
await createTransferOperation({ from, ...transfer })
);
}
return { network: TESTNET.name, broadcast: false, operations };
}
View complete file · Run example
Pair two atomic transfers¶
export async function atomicTransferPair(from, first, second) {
return buildBatch(from, [first, second]);
}
View complete file · Run example
This only groups two operations; it is not a trustless swap protocol. A real swap also needs authorization and counterparty logic in a contract.
Describe related contract updates¶
export function describeAtomicUpdates(updates) {
return {
network: TESTNET.name,
broadcast: false,
atomic: true,
updates,
};
}
View complete file · Run example
Replace each description with a tested contract operation before signing.
Batch recipients¶
export async function batchTokenTransfers(from, recipients) {
return buildBatch(
from,
recipients.map(({ address, amount }) => ({ to: address, amount }))
);
}
View complete file · Run example
Size resource limits deliberately¶
export function multiOperationOptions(operationCount) {
if (operationCount < 1) throw new Error("At least one operation is required");
return { rcLimit: String(100_000_000 * operationCount), broadcast: false };
}
View complete file · Run example
The calculation is a conservative example, not a network estimate. Simulate your actual operations and set an appropriate limit. Keep batches reasonably sized, validate every recipient, and inspect the full transaction before broadcast.