Hello everyone ,
I am using stellar sdk to send payments from one account to another. When i send payment one by one , there is no error . everything works fine. However when i try to send payments in batch i get error "tx_bad_seq" randomly for few records. I understand the reason for the error , but how can i avoid them ? also the document says even if i get "tx_bad_seq" , the transaction may be valid in future. This is very risky for payments? any help here will be highly appreciated! thanks!
var transaction = new StellarSdk.TransactionBuilder(publickey)
            .addOperation(
              StellarSdk.Operation.payment({
                destination: destAcct,
                asset: StellarSdk.Asset.native(),
                amount: amountToTransfer
              })
            )
            .setTimeout(5000)
            .build();
      transaction.sign(
        StellarSdk.Keypair.fromSecret(SecretKey)
      );
      return server.submitTransaction(transaction)