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
XDR is a binary encoding of structured data. It is represented as a base 64 encoded String in transaction responses.
Some options:
You can decode base 64 encoded XDR using the laboratory.
The JavaScript SDK provides instructions to deserialise the Base 64 XDR into JSON.
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).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)
-
As you know, but for the benefit of future readers, this capability has since been implemented in the Java SDK.– SynessoCommented Sep 10, 2018 at 21:35