REST API endpoint for verifying transactions on mainnet and testnet using transaction hash

Thanks you som much @limemloh, this was helpful and almost there. I have been able to extract my data only that it seems to be encoded

amount: "1000000"
data: (145) [123n, 34n, 117n, 115n, 101n, 114n, 73n, 100n, 34n, 58n, 34n, 53n, 97n, 54n, 50n, 56n, 49n, 98n, 56n, 45n, 97n, 57n, 102n, 102n, 45n, 52n, 102n, 53n, 56n, 45n, 57n, 55n, 49n, 52n, 45n, 50n, 53n, 52n, 55n, 100n, 102n, 52n, 57n, 100n, 52n, 49n, 97n, 34n, 44n, 34n, 116n, 101n, 97n, 109n, 73n, 100n, 34n, 58n, 34n, 54n, 100n, 52n, 98n, 100n, 98n, 101n, 48n, 45n, 52n, 99n, 56n, 98n, 45n, 52n, 98n, 54n, 49n, 45n, 98n, 51n, 52n, 97n, 45n, 97n, 98n, 57n, 99n, 50n, 55n, 98n, 102n, 101n, 57n, 97n, 53n, 34n, 44n, 34n, 103n, 97n, …]
from:  {Account: Array(1)}
to: Account: Array(1)}
token_id: ""

The final hurdle for me, is to decode this data back to JSON. If I can atleast get it to Hexstring, then I can get it to JSON, but I’m not sure how to convert the BigInt array returned to either Hexstring or JSON. Any Idea how I can do this?

Converting this to JSON will require a schema or something else to define how the bytes are translated. So I might be able to help there if you can share more information on what the data represents.

For now, I can at least help to convert it into a hex string

In NodeJS you can simply do:

const hexString = Buffer.from(transferParameter.data).toString("hex");

In the browser the above does not work, since Buffer is a NodeJS thing (unless you pull in a package on npm).
Instead, we could take advantage of some code related to the Parameter type in @concordium/web-sdk:

import {Parameter} from "@concordium/web-sdk";

...

const hexString = Parameter.toHexString(Parameter.fromBufferUnchecked(new Uint8Array(transferParameter.data)));

@limemloh trying to do this

Parameter.toHexString(Parameter.fromBufferUnchecked(new Uint8Array(data)));

fails with an error

 Cannot convert a BigInt value to a number at new Uint8Array

However I able to do this

const normalizedDataBuffer = data.map(bigInt => parseInt(bigInt.toString()))
const hexString = Parameter.toHexString(Parameter.fromBufferUnchecked(normalizedDataBuffer));

and this gave me the Hexstring for my data. Thank you so much for help, I really appreciate! :raised_hands:

1 Like