Fetching transaction details in expres

I am creating rest api where i will get withdraw txn but when I am getting different format in console and postman app. Refer the screenshot.How shall I manage it?



s

The transaction object you’re trying to send is an object with byte arrays inside Uint8Array.
It looks like you’re trying to serialize it into JSON.
This will cause issues as JSON does not support byte arrays.

Instead, we strongly recommend to serialize transactions in msgpack, which is how all transactions on Algorand are serialized.
If you need the REST API to output a JSON object, you can do for example:

{
   "transaction": <base64 of the msgpack encoding>
}

See how for example ARC-1 serializes transactions:

const txn1B64 = Buffer.from(txn1.toByte()).toString("base64");

assuming txn1 is the transaction you want.
txn1B64 is then what you want your REST API to return.

I will be using rest api so shall i follow approach

  1. const txn1B64 = Buffer.from(txn1.toByte()).toString(“base64”);
  2. const encodedtxn = algosdk.encodeUnsignedTransaction(txn)

which one shall i prefer?

txn1.toByte() is equivalent to algosdk.encodeUnsignedTransaction(txn1)
You still need to convert to Base64 in the second case:

const encodedtxn = Buffer.from(algosdk.encodeUnsignedTransaction(txn)).toString("base64");