5

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.

1 Answer 1

6

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)
1
  • As you know, but for the benefit of future readers, this capability has since been implemented in the Java SDK.
    – Synesso
    Commented Sep 10, 2018 at 21:35

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.