I queried a transaction result using:
curl http://localhost:3000/tendermint/tx?hash=0xCDD76608F774BD29CDED2EBD30E94FB66CEF73A9
and then fetch the transaction content 'tx' in the returned JSON object.
// tx was extracted from the above returned JSON object
let tx = 'AAABF3siZnJvbSI6eyJhbW91bnQiOjEwMCwicHVia2V5IjoiOmJhc2U2NDpBNmZUNjFvRnlLNG1HZExnd21xSU5ubE55c1NIQ1BDRm9vb2Jod1BTamY2UCIsInNlcXVlbmNlIjowLCJzaWduYXR1cmUiOiI6YmFzZTY0OjFGdmZvZUlLTWlDd1A2NE9IVHd2MHhjeGk3elVBRUNRTkc1NnpnR1lYdkV2UEMvallTcGUvZjVsM0pjRHRNQUl0bHNZMGtrSEZrbHNxTW82Tm9Qa0xBPT0ifSwidG8iOlt7ImFkZHJlc3MiOiJEVkFTNnFzSkxQM3lkUFd0UndkaXNIaXFmVkdtYW1UWVkiLCJhbW91bnQiOjEwMH1dfQAACMs'
I decoded it with
let value = Buffer.from(tx, 'base64').toString('utf-8')
console.log(value)
and then it printed the following result which contains garbled characters at the end:
{"from":{"amount":100,"pubkey":":base64:A6fT61oFyK4mGdLgwmqINnlNysSHCPCFooobhwPSjf6P","sequence":0,"signature":":base64:1FvfoeIKMiCwP64OHTwv0xcxi7zUAECQNG56zgGYXvEvPC/jYSpe/f5l3JcDtMAItlsY0kkHFklsqMo6NoPkLA=="},"to":[{"address":"DVAS6qsJLP3ydPWtRwdisHiqfVGmamTYY","amount":100}]�
What's the correct way to decode a transaction?
------------- More details ----------------------
I am using Lotion to build my app. Much thanks to Chandrika's answer.
If you are using Lotion, you can do as follows to get the decoded transaction.
let encodeTx = require('./tx-encoding.js')
let bf = Buffer.from(tx, 'base64')
let txn = encodeTx.decode(bf)
Where tx
: encoded tx you got by querying tendermint.
txn
will be the required decoded transaction.