5

I am using @taquito to build and sign a transaction. But before I send it I want to decode it to check my destination address, amount etc like you would normally do for other blockchains.

Not sure how to do it, but I signed a request using my ED25519 signing key. The signing was successful and the sbytes I got in return was

008f1d96e2783258ff663f03dacfe946c026a5d194c73d1987b3da73fadea7d46c008cb5baedee4dc3ec261dfcf57a9600bb0a8e26c0f00bdd85a0018452ac02e0a712000153957451d3cc83a71e26b65ea2391a1b16713d2d009595facf847a72b4c3fe231c0e4185e68e9b2875aa3c639382c86bcf0af23699f47fe66a6550ade936a5b59d5919ad20703885750314e0c368b277de39e7d10a

I've read through some articles but could not find an exact way to do this and whatever I tried did not exactly yield what I wanted, which either means that I do not know how to decode the transaction, or my sbytes are wrong. Can anyone please explain on how do I decode this raw transaction using a Javascript/Typescript library to get stuff like

fromAddress toAddress amount etc. and if my signed transaction is correct. This is for testnet.

3 Answers 3

7

Taquito can parse forged bytes using the parse() method in the @taquito/local-forging package.

TypeDocs are here. You can see the unit tests here.

Implementation to decode a signed transaction:

const { localForger } = require('@taquito/local-forging');

const sbytes = '008f1d96e2783258ff663f03dacfe946c026a5d194c73d1987b3da73fadea7d46c008cb5baedee4dc3ec261dfcf57a9600bb0a8e26c0f00bdd85a0018452ac02e0a712000153957451d3cc83a71e26b65ea2391a1b16713d2d009595facf847a72b4c3fe231c0e4185e68e9b2875aa3c639382c86bcf0af23699f47fe66a6550ade936a5b59d5919ad20703885750314e0c368b277de39e7d10a';

async function decode() {
    const unsignedPart = sbytes.substring(0, sbytes.length - 128); // Removing last 128 characters as that is the signature
    const decoded = await localForger.parse(unsignedPart);
    console.log(decoded);
}

decode(); 
7

You can use the tezos-codec binary to decode this:

tezos-codec decode 006-PsCARTHA.operation from 008f1d96e2783258ff663f03dacfe946c026a5d194c73d1987b3da73fadea7d46c008cb5baedee4dc3ec261dfcf57a9600bb0a8e26c0f00bdd85a0018452ac02e0a712000153957451d3cc83a71e26b65ea2391a1b16713d2d009595facf847a72b4c3fe231c0e4185e68e9b2875aa3c639382c86bcf0af23699f47fe66a6550ade936a5b59d5919ad20703885750314e0c368b277de39e7d10a

which yields

{ "branch": "BKiXcfN1ZTXnNNbTWSRArSWzVFc6om7radWq5mTqGX6rY4P2Uhe",
  "contents":
    [ { "kind": "transaction",
        "source": "tz1YU2zoyCkXPKEA4jknSpCpMs7yUndVNe3S", "fee": "1520",
        "counter": "2622173", "gas_limit": "10500", "storage_limit": "300",
        "amount": "300000",
        "destination": "tz2FwBnXhuXvPAUcr1aF3uX84Z6JELxrdYxD" } ],
  "signature":
    "sighZMqWz5G8drK1VTsmTnQBFEQ9kxQQxL88NFh8UaqDEJ3R3mzgR3g81azadZ9saPwsWga3kEPsyfbzrXm6ueuDvx3pQ5Q9" }

You can get more details about tezos-codec in its manual (tezos-codec man -v 3)

2
2

You can use the RPC endpoint: /chains/main/blocks/head/helpers/parse/operations to do that.

Example:

await axios.post(
        `${nodeURL}/chains/main/blocks/head/helpers/parse/operations`,
            parseOperationBytesData,
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            }
        )
2
  • Can you be a bit more explicit and show how parseOperationBytesData looks? Commented Sep 20, 2020 at 14:14
  • parseOperationByteData should be like {"operations":[{"data":"6c00c800bfcc4fdca7ad8bfffa67f8378ab6bfe09d95a003bfb517f70b64a08d060000e02be16f594575ad492b7e991a1e2ee16af96eb4005c947f2ba2b1abbf04bf7785cf39322a5a7c24ae0e46da130bec9636ef018f61c9148e691dc58b8db96d9dd3d432a358ff63e81ac96ce7fee96ee5f3c7d3810e","branch":"BKrbEReHWBkJ8RDyhj59zJ6vjdCfJoVjMVQADLY6PspDEnCDXLs"}]} where data is the raw transaction without the signature and without the first 64 characters (block_hash)
    – onepix
    Commented Jun 14, 2021 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.