0

Can please someone explain to me why the following code works fine:

const transaction = new StellarSDK.TransactionBuilder(pAccount, txOptions)

transaction.addOperation(StellarSDK.Operation.payment(paymentTo[0]))
transaction.addOperation(StellarSDK.Operation.payment(paymentTo[1]))
transaction.addOperation(StellarSDK.Operation.payment(paymentTo[2]))

transaction.setTimeout(60);
transaction.build();
transaction.sign(StellarSDK.Keypair.fromSecret(pSecret));

whereas, if I loop over addOperation, in the exact same setting, I get the error 'transaction.sign is not a function'?

const transaction = new StellarSDK.TransactionBuilder(pAccount, txOptions)

for (let i = 0; i < 3; i++) { 
    transaction.addOperation(StellarSDK.Operation.payment(paymentTo[i]));
}

transaction.setTimeout(60);
transaction.build();
transaction.sign(StellarSDK.Keypair.fromSecret(pSecret));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.