2

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);

I have checked the post at Error tx_bad_seq , but the node js code pointed out does not demonstrate how to get sequence number and pass it to transaction

2
  • Do you build and submit a transaction (the code you show) from within a loop? In that case you need to await the promise returned by submitTransaction.
    – Francesco
    Jan 27, 2020 at 22:17
  • yes i am already using await
    – Ether
    Jan 31, 2020 at 6:10

2 Answers 2

1

i read on channels and went through other similar questions , i created one new channel account and to make it active transferred 1 lumen into channel account , my code now looks like

 var transaction =
          new StellarSdk.TransactionBuilder(channelAccount)
            .addOperation(StellarSdk.Operation.payment({
              source: sourcePublicKey,
              destination: destAcct,
              asset: StellarSdk.Asset.native(),
              amount: config.amountToTransfer
            }))
            // Wait a maximum of three minutes for the transaction
            .setTimeout(180)
            .build();


          transaction.sign(StellarSdk.Keypair.fromSecret(sourceSecretKey));  // base account must sign to approve the payment which is merchant account
          transaction.sign(StellarSdk.Keypair.fromSecret(channelSecretKey)); 

However i get "tx_insufficient_balance" error in response , i want all fees to go through sourcePublicKey which has more then 100 lumens . am i missing something here?

0

To avoid tx_bad_seq error during payment, you should use channel account of sender account. Channel account is going to submit the transaction on behalf of sender account. Channel account and sender account both sign the transaction. I am sharing the link below.

https://www.stellar.org/developers/guides/channels.html

2
  • i read on channels and went through other similar questions , i created one channel account to make it active transferred 1 lumen in this ,
    – Ether
    Jan 31, 2020 at 9:33
  • please check my updated code below . As there is limit to characters in comments , i have added new code below
    – Ether
    Jan 31, 2020 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.