0

I am creating a multi-sign transaction. When I am submitting the transaction to Stellar, response.isSuccess() returns false. Could anyone tell me where I am going wrong? link https://www.stellar.org/developers/js-stellar-base/reference/base-examples.html#multi-signature-account

public static void main(String[] args) {
    Network.useTestNetwork();
    Server server = new Server("https://horizon-testnet.stellar.org");

    KeyPair source = KeyPair.fromSecretSeed("SC4EJSKMHQLHRUWFYC7O62OP2QPQ2HD7IOXCHKR2STVPAQ6E5MBXXRAI");

    KeyPair source1 = KeyPair.fromSecretSeed("SCR5ARAIDZ6EW4NRVFUP35CY444S3D4H52GIVKW46D736UFFVQFLLVY4");
    KeyPair secondary1 = KeyPair.fromAccountId("GAU3GFO7L3TECSZ2ARAHACTQ44QKHKU355PHWBLRIWHXIDXBRHMNOYVQ");

    KeyPair destination = KeyPair.fromAccountId("GCFOSKTU4N4OPOXFGA473V2DG36QBCHNPHXOLU4W2BZL5TZH4GCZS5BN");

    try {
        server.accounts().account(destination);
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    AccountResponse sourceAccount = null;
    try {
        sourceAccount = server.accounts().account(source);
        sourceAccount = server.accounts().account(source1);
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    Transaction transaction = new Transaction.Builder(sourceAccount)
            .addOperation(new SetOptionsOperation.Builder().setSigner(secondary1.getXdrSignerKey(), 1)
                    .setMasterKeyWeight(1).setLowThreshold(0)
                    .setMediumThreshold(2).setHighThreshold(2).build())
            .build();
    transaction.sign(source);
    transaction = new Transaction.Builder(sourceAccount)
            .addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), "11").build())
            .addMemo(Memo.text("Test Transaction"))
            .build();

    transaction.sign(source);
    transaction.sign(source1);
    try {
        SubmitTransactionResponse response = server.submitTransaction(transaction);

        System.out.println(response.isSuccess());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

1 Answer 1

1

You are getting an error because of a bad sequence number. I know this because I decoded response.getResultXdr(). Here are some things you should know:

  1. When you call sourceAccount = server.accounts().account(source), sourceAccount will have the correct sequence number.
  2. When you call build(), the TransactionBuilder will increment the account's sequence number by 1, so that the account is ready to participate in a new transaction
  3. Because you never submit the first transaction, that sequence number is never used.
  4. When you reassign transaction = new Transaction.Builder(sourceAccount), sourceAccount has the incremented sequence number.
  5. When you submit the second transaction, the network rejects it because it never received the preceding sequence number.

Although I'm not sure what you're trying to do, you need to make sure that you call build once before calling submitTransaction.

1

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.