2

The below code is the multisig transaction to submit to stellar horizon testnet. When I am submitting the transaction, I am getting the submission failed error.

 var alice_public_key = 'GD2HPONSMOTEJQUE2WIUBPMWZ7WPAE7EBLW2RRD2XH6CIJHKCZKAYMZ3';
var alice_seed = 'SCQUFZIFKMF3CYXAYKPKBQZRF33O3YKJMQXL63PVW7O66GBQOTVKR3A5';

second_public_addr = 'GAYSO44LPX32TKXS5QWJ7ZVKW6DF42NOE22ZJJPXZZMAUIEVKKP5MYV5'
second_private_key = 'SAFSKKF4Q7HBO65HPTZ5I23HOJZ2WEQ4H4YRBSDQGQA222EWK5PPFZI4'

var destinationId = 'GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5';


var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

server.loadAccount(destinationId)
.catch(StellarSdk.NotFoundError, function (error) {
    throw new Error('The destination account does not exist!');
  })
 .then(function() {

   server.loadAccount(alice_public_key)
  .then(function(account) {
    // console.log(account.sequence)
    var rootKeypair = StellarSdk.Keypair.fromSecret(alice_seed) 
    var account = new StellarSdk.Account(alice_public_key, account.sequence);
    var transaction = new StellarSdk.TransactionBuilder(account)
  .addOperation(StellarSdk.Operation.setOptions({
    signer: {
      ed25519PublicKey: second_public_addr,
      weight: 1
    }
  }))
  .addOperation(StellarSdk.Operation.setOptions({
    masterWeight: 1, // set master key weight
    lowThreshold: 1,
    medThreshold: 2, // a payment is medium threshold
    highThreshold: 2 // make sure to have enough weight to add up to the high threshold!
  }))
  .build();

  transaction.sign(rootKeypair); 
  // var x_transaction = transaction;
  // console.log(x_transaction)
  var transaction = new StellarSdk.TransactionBuilder(account)
    .addOperation(StellarSdk.Operation.payment({
        destination: destinationId,
        asset: StellarSdk.Asset.native(),
        amount: "10" // 2000 XLM
    }))
    .addMemo(StellarSdk.Memo.text('Test Transaction'))
    .build();
    var secondKeypair = StellarSdk.Keypair.fromSecret(second_private_key);

    transaction.sign(rootKeypair);
    transaction.sign(secondKeypair);
    console.log(transaction)

    server.submitTransaction(transaction)
    .then(function (transactionResult) {
        console.log(transactionResult);
    })
    .catch(function (err) {
        console.error(err);
    });

 });

  })

ERROR:

{ [BadResponseError: Transaction submission failed. Server responded: 400 Bad Request]
  name: 'BadResponseError',
  message: 'Transaction submission failed. Server responded: 400 Bad Request',
  data: 
   { type: 'https://stellar.org/horizon-errors/transaction_failed',
     title: 'Transaction Failed',
     status: 400,
     detail: 'The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details.  Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html',
     extras: 
      { envelope_xdr: 'AAAAAPR3ubJjpkTChNWRQL2Wz+zwE+QK7ajEern8JCTqFlQMAAAAZABrCz0AAAAIAAAAAAAAAAEAAAAQVGVzdCBUcmFuc2FjdGlvbgAAAAEAAAAAAAAAAQAAAACxymL+yL1Pze4i36tOuCt15BqNw6/XhAT4br3o8p0zpAAAAAAAAAAABfXhAAAAAAAAAAAC6hZUDAAAAECywXEM2F1RUKIKgP5rfnhey0Yr3vjuJdjZMGkExSb7zE2qbrYxs3hBN2Qk/ZsNy9SSbav/79vgNb3ePv5AvFcJ8p0zpAAAAEDGsDwv0p/714rrzSrdhNZ+sP0qr3wWp36VWUnbkzIlhievvJ3Tie7P6iP7iVU5Vobiwh+2mcaz5vLnSFnu3sgG',
        result_codes: [Object],
        result_xdr: 'AAAAAAAAAAD////7AAAAAA==' } } }
2
  • One question first, which transaction would you like to submit? You declared "var transaction" twice but only submitted once at the end.
    – cesarm
    Commented Mar 13, 2018 at 9:35
  • I tested the 2 transactions separately, the 1st one is malformed; 2nd one passed: horizon-testnet.stellar.org/transactions/…
    – cesarm
    Commented Mar 13, 2018 at 9:38

2 Answers 2

1

(I'll start anew here)

4 issues spotted:


Issue 1

I tried at Laboratory with doing a simple "Payment" from {alice_public_key} to a {second_public_addr}.

Signed with and submitted this transaction, returning "op_bad_auth". 2 possibilities: (1) "alice_seed" is not the correct pair for "alice_public_key", (2) Your account already has multisig set up, so that the operation cannot proceed, as there are not enough signers (i.e. access right).


Issue [2]

A transaction will fail, when any one of the operations is considered invalid. Invalidity can be invalid data (e.g. Pay negative amount), wrong signature, too many (irrelevant) signatures, etc.

There are in total three ".addOperation()". At the bottom, you signied with 2 accounts and . I assume your three accounts were all freshly created, so they were not related before "setOptions", i.e.

MasterWeight = lowThreshold = medThreshold = highThreshold = 1 

no other signers for Alice, except herself

When {alice} is the only available signer but you sign with 2 accounts, the system FAILS your transaction because you have an unnecessary (extra) signer {second}.

You may try this extracted portion of your code and verify the issue.

server.loadAccount(alice_public_key).then(function(account) {
// console.log(account.sequence)
var rootKeypair = StellarSdk.Keypair.fromSecret(alice_seed) 
var account = new StellarSdk.Account(alice_public_key, account.sequence);

var transaction = new StellarSdk.TransactionBuilder(account)
.addOperation(StellarSdk.Operation.payment({
    destination: destinationId,
    asset: StellarSdk.Asset.native(),
    amount: "10" // 2000 XLM
}))
.addMemo(StellarSdk.Memo.text('Test Transaction'))
.build();
var secondKeypair = StellarSdk.Keypair.fromSecret(second_private_key);

transaction.sign(rootKeypair);
transaction.sign(secondKeypair);

server.submitTransaction(transaction)
.then(function (transactionResult) {
    console.log(transactionResult);
})
.catch(function (err) {
    console.error(err);
})
})

Result will be "result_xdr: 'AAAAAAAAAGT/////AAAAAf////8AAAAA' } } }", which can be decoded to [opBadAuth].


Issue [3]

As I pointed out previously, you re-declared "var transaction" in the same function. Therefore, only one would be valid. Maybe you can change them to "transaction1" & "transaction2", but remember to submitTx for both separately.


Issue [4]

I think you also need this line of code to make things work.

StellarSdk.Network.useTestNetwork();

Advice: Try to do the transaction on Laboratory before coding the programme. The Stellar system is not explicitly documented, so you need to understand it by working with hands :)

Reference for "threshold":

https://www.stellar.org/developers/guides/concepts/multi-sig.html#thresholds

7
  • I'll make it short for your work: Create 3 new pairs of keys, and sign ONLY with alice. Also, rename your "var transaction" and submit them separately. These should be enough to make your codes work.
    – cesarm
    Commented Mar 15, 2018 at 2:03
  • 1
    First of all, I want to appreciate you. Thanks a lot for helping me. I haven't thought that I would get such kind of a help at the beginning. I was lucky that you responded to my question. You saved my job. I have some questions to clarify the entire concept now. Please don't mind that I am troubling you. I haven't got any resources or any help so this is the only way I can get help.
    – merklexy
    Commented Mar 15, 2018 at 10:04
  • 1
    Everything is perfectly working fine now. The only thing I have to know is how do I explicitly mention the fee? I want to mention the fee explicitly. How and where to mention the fee explicitly?
    – merklexy
    Commented Mar 15, 2018 at 14:56
  • you're welcome, it actually took me several months until I could understand the bigger picture, so no worry it takes time. But what do you mean by mention the fee explicitly?
    – cesarm
    Commented Mar 16, 2018 at 1:48
  • When submitting a transaction, we are not mentioning how much fee are we actually willing to pay. It automatically takes the fee. In my use case, how to mention the fee explicitly. I will add the code to the below comment in which we are not mentioning the fee at all.
    – merklexy
    Commented Mar 16, 2018 at 7:35
3

The field result_xdr decodes to txBadSeq indicating that you've got a bad sequence number on that transaction.

0

Your Answer

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

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