4

I want to convert the XDR fromat of the transaction to text using JS or java SDK in stellar.Or if there are any methods outside stellar also fine.

5

XDR is a binary encoding of structured data. It is represented as a base 64 encoded String in transaction responses.

Some options:

  1. You can decode base 64 encoded XDR using the laboratory.

  2. The JavaScript SDK provides instructions to deserialise the Base 64 XDR into JSON.

  3. If you can use the Scala SDK you can call SignedTransaction.decodeXDR(base64)(TestNetwork) to get an object that you can inspect. (Eventually this will decode to case classes, which display all fields when printed - but it's not ready in the SDK yet) (Disclaimer: I am the author).

  4. The following (untested) Java code deserialises the base 64 TransactionResponse to an object to the same as #3.

.

import java.io.ByteArrayInputStream;
import java.util.Base64;
import org.stellar.sdk.xdr.*;

Byte[] bytes = Base64.getDecoder().decode(base64);
XdrDataInputStream in = new XdrDataInputStream(new ByteArrayInputStream(bytes));
TransactionEnvelope.decode(in)
  • Thanks for the reply. Okay so how can i sign the transaction java if i only have xdr. I can able to sign it through laboratory. And able to decode based on your answer. but i need to sign and submit as well. – Sharmilan May 3 '18 at 6:21
  • As you know, but for the benefit of future readers, this capability has since been implemented in the Java SDK. – Synesso Sep 10 '18 at 21:35

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.