1

I am getting the following Exception while performing send transaction using the Java Stellar SDK.

This is my send transaction code:

import org.stellar.sdk.AssetTypeNative;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.Memo;
import org.stellar.sdk.Network;
import org.stellar.sdk.PaymentOperation;
import org.stellar.sdk.Server;

import org.stellar.sdk.Transaction;
import org.stellar.sdk.responses.AccountResponse;
import org.stellar.sdk.responses.SubmitTransactionResponse;

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

            KeyPair source = KeyPair.fromSecretSeed("SXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            KeyPair destination = KeyPair.fromAccountId("GXXXXXXXXXXXXXXXXXXXXXXXXX");


            try {
                server.accounts().account(destination);
            }
            catch(Exception e) {
                System.out.println(e.getMessage());
                return;
            }

            AccountResponse sourceAccount;
            try {
                sourceAccount = server.accounts().account(source);
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return;
            }

            Transaction transaction = new Transaction.Builder(sourceAccount)
                    .addOperation(new PaymentOperation.Builder(destination, new AssetTypeNative(), "10").build())
                    .addMemo(Memo.text("hello"))
                    .build();
            // Sign the transaction to prove you are actually the person sending it.

            transaction.sign(source);


            // And finally, send it off to Stellar!
            try {
              SubmitTransactionResponse response = server.submitTransaction(transaction);
              System.out.println("Success!");
            } catch (Exception e) {
              System.out.println("Something went wrong!");
              System.out.println(e.getMessage());
            }
    }

}

I am getting exception:

Exception in thread "main" java.lang.RuntimeException: TimeBounds has to be set or you must call setTimeout(TIMEOUT_INFINITE).
    at org.stellar.sdk.Transaction$Builder.build(Transaction.java:385)
    at com.apiservice.controller.sendTransaction.main(sendTransaction.java:45)

Here's my pom.xml

<repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.stellar</groupId>
            <artifactId>java-stellar-sdk</artifactId>
            <version>0.2.0</version>
        </dependency>



    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
2
  • I'm no java-sdk expert but assume you have to new Transaction.Builder().setTimeout(60).[...].build()
    – sui
    Commented Apr 15, 2019 at 7:29
  • The version of the SDK you're using is 1 year old. Please upgrade to 0.6.0, or whatever is the latest at time of reading at github.com/stellar/java-stellar-sdk/releases
    – Synesso
    Commented Apr 18, 2019 at 10:24

2 Answers 2

0

The exception is clear. You need to call

.setTimeout(Transaction.Builder.TIMEOUT_INFINITE)

In the builder chain.

1
  • I would encourage the OP to set a short specific timeout, rather than TIMEOUT_INFINITE (see my answer for rationale). Commented Apr 18, 2019 at 18:31
0

Timebounds were introduced to the Java SDK in July 2017. The SDKs require you to specify timebounds, because once a transaction is sent to the network, there's no guarantee that (if the network is busy) it will be included in the next ledger. If it doesn't make it for several consecutive ledgers, the transaction is dropped.

From the perspective of the client, this uncertainty is difficult to manage. By providing timebounds, you explicitly indicate the window of validity for the transaction. If enough time has passed and you've exceeded the upper timebound that you provided, then you know that your submitted transaction will never be successful, and you can take appropriate action (e.g. by submitting another one, with the same sequence number).

Most developers will want to set sensible upper timebounds. TIMEOUT_INFINITE is intended to be used rarely. It is helpful for smart contracts or transactions that will execute in the far future.

For completeness: the lower timebound provides a way to indicate that a transaction cannot be valid until a certain time in the future. This is also more rarely used, as it is typically related to smart contracts.

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.