1

I receive an HTTP 400 error from the /transactions endpoint on public Horizon when running this code:

try {
    Network.usePublicNetwork();
    Server server = new Server("https://horizon.stellar.org");
    KeyPair source = KeyPair.fromSecretSeed(CoinConfig.XLM_SECRET);
    KeyPair destination = KeyPair.fromAccountId(accountsId);
    server.accounts().account(destination); 
    AccountResponse sourceAccount = server.accounts().account(source);
    Transaction.Builder builder = new Transaction.Builder(sourceAccount);
    builder.addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), money).build());
    builder.addMemo(Memo.text(label));
    Transaction transaction = builder.build();
    transaction.sign(source);
    SubmitTransactionResponse response = server.submitTransaction(transaction);
    String hash = "";
    if (response.isSuccess()) {
        hash = response.getHash();
    }
    System.out.println(hash);
    return hash;
} catch (Exception e) {
    throw new ErrorException("Xlm Transaction Failure!", e);
}

Submission return:Response{protocol=http/1.1, code=400, message=Bad Request, url=https://horizon.stellar.org/transactions}

  • Please copy & paste the stack trace or full error details. – Synesso Jul 24 '18 at 8:03
  • All details are in the response body of horizon. You should check it first. – Bartek Nowotarski Aug 7 '18 at 14:24
1

I am able to run a modified version of your code successfully on testnet:

Network.useTestNetwork();
Server server = new Server("https://horizon-testnet.stellar.org/");
KeyPair source = KeyPair.fromSecretSeed("SBKL5C3CZ5OURFFSAVTVFFGDPLXPOBIAM2IHETXMERNUG3U5VHH34HWA");
KeyPair destination = KeyPair.fromAccountId("GD2VTA6Y3REXSC4NTWEICM3I3WNFAP5DKEJRQDMW4BLGKFWVDIBTPWND");
server.accounts().account(destination);
AccountResponse sourceAccount = server.accounts().account(source);
Transaction.Builder builder = new Transaction.Builder(sourceAccount);
builder.addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), "100").build());
builder.addMemo(Memo.text("SomeMemo"));
Transaction transaction = builder.build();
transaction.sign(source);
SubmitTransactionResponse response = server.submitTransaction(transaction);
String hash = "";
if (response.isSuccess()) {
    hash = response.getHash();
}
System.out.println(hash);

It's difficult to know what your issue is without seeing the error message in full.

0

You should catch the exception such as in


try {
  SubmitTransactionResponse response = server.submitTransaction(transaction);
  System.out.println("Success!");
  System.out.println(response);
} catch (Exception e) {
  System.out.println("Something went wrong!");
  System.out.println(e.getMessage());
}
(Code from https://www.stellar.org/developers/guides/get-started/transactions.html)

An error 400 means horizon is not accepting your transaction for whatever reason. The exception message should contains details about why the transaction has been rejected.

  • 1
    This will provide even less information that what they'll get by throwing ErrorException. – Synesso Jul 24 '18 at 20:00
  • Well I don't know about Java but in JavaScript the horizon response contains fields that give more details. – Mister Ticot Jul 25 '18 at 20:05
  • No worries. OP's code will throw the exception, causing the message, full stack trace and any chained exceptions to be printed to stderr – Synesso Jul 25 '18 at 21:59

Your Answer

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

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