Parser Basics
Parse transactions and rebuild
The TxParser
is a tool where you can parse the typical transaction CBOR hex back into the MeshTxBuilderBody
. With such capability, you can proceed with rebuilding a transaction or examing the with unit testing frameworks.
In this page, we will cover how to initialize the TxParser
.
Initialize Tx Parser
To start parsing transaction, you need to first initialize TxParser
:
There are 2 fields to pass in to initialized TxParser
:
serializer
: The serializer instance that will be used for parsing transactionfetcher
(optional):TxParser
requires all inputUTxO
information provided since the transaction CBOR hex only preserves transaction hash and output index. When you are not providing all inputUTxO
information, thefetcher
instance is used to fetch the missingUTxO
Rebuild Transaction
To parse a transaction, you only need:
With the parsed txBuilderBody
in type MeshTxBuilderBody
, you can proceed with adding / removing elements and rebuilding the transaction.
There are 2 necessary fields to pass in:
txHex
: The transaction CBOR to be parsedprovidedUtxos
: The input information, for all inputs, reference inputs, and collateral. You can either construct it manually or obtain it fromfetcher
.
Unit Testing Transaction
To unit test a transaction, you can parse the transaction and then convert the instance to TxTester
:
The detailed testing APIs can be found in the documentation.