Batch processing
January 15, 2021 ยท View on GitHub
In order to process huge amount of Transfer Asset and Send Data requests you can either use single transactions and handle it via the suggested architecture below or use Polkadot utility.batch method:
1. Architecture approach:
.png)
2. Using Polkadot utility.batch method:
// construct a list of transactions we want to batch
const txs = [
api.tx.balances.transfer(addrBob, 12345),
api.tx.balances.transfer(addrEve, 12345),
api.tx.staking.unbond(12345)
];
// construct the batch and send the transactions
api.tx.utility
.batch(txs)
.signAndSend(sender, ({ status }) => {
if (status.isInBlock) {
console.log(`included in ${status.asInBlock}`);
}
});
Source is here.
Try using Test Scripts to check how it works on practise.