Method to Serialize a JSON to Transaction

Goal: serialize a JSON transaction object into a binary transaction file

Steps to generate JSON transaction file

goal clerk send -a 1000 -f $FROM -t $TO -o $BINARY_TX -d $DATA
goal clerk inspect -f $BINARY_TX >> $JSON_TX
cat $JSON_TX # will display the JSON results

What methods are provided to serialize the $JSON_TX into a $BINARY_TX?

For testing purposes, one may desire to manually modify transaction data, serialize the JSON and broadcast the results:

goal clerk rawsend -f $BINARY_TX -d $DATA

Guidance within any of the SDKs is appreciated. Iā€™m just not quite sure where to look or what to search for.

1 Like

goal clerk inspect not only de-serializes but also beautifies the output: it adds some header filename[0] before each transaction, it adds checksum to addresses, and encodes fields either using Base32 or Base64 (depending on the field name).

If you want only to de-serialize the transactions, you can use msgpacktool -d -b32 < $BINARY_TX > $JSON_TX. Then you can re-serialize them using msgpacktool -e -b32 < $JSON_TX > $NEW_BINARY_TX.

Transactions files consist in a concatenation msgpack-encoded SignedTransaction objects (https://github.com/algorand/go-algorand-sdk/blob/bc0af1afd700d7f255ae617feeb0b03040c2c2a7/types/transaction.go#L23 in the Go SDK). For the Go SDK, encoding and decoding functions are provided in https://github.com/algorand/go-algorand-sdk/blob/master/encoding/msgpack/msgpack.go

2 Likes

Exactly the answer I was looking for @fabrice. Thanks very much for the introduction to the msgpacktool. Resolved