Forge & Parse

Operation shell

Before the operations can be forged into its binary repressentation and signed, we must encapsulate the operations inside a shell that contains the operations and a branch.

{
    "branch": $hash,
    "contents": $operations
}

The branch value should be the hash of the most recent block. If a branch is older than 50 blocks (minutes) the operations will be rejected by the nodes. This is mainly of interest to have in mind when dealing with offline/remote signing or a growing mempool.

An example of an operation shell with a single operation:

{
    "branch": "BLTUcKtBkLmQGRoXjiLEXcZHS9wR5Mgcq9sZkxU3DdLMVwy2wMu",
    "contents":
        [
            {
                "kind": "transaction",
                "source": "tz1WhHx7DMH8cKyXe5dv9cDy5wzFJX2wfTPB",
                "fee": "1350",
                "counter": "74227",
                "gas_limit": "10600",
                "storage_limit": "277",
                "amount": "3528000",
                "destination": "KT1Ecay6hLAsGmVSaRawzF1iNt8beuk1djDF"
            }
        ]
}

Forging

By forging an operation shell the JSON object is encoded into its binary repressentation. The forging can be done remotely by a RPC node or done locally. When forging remotely, it’s important that the node is trusted. Forging the operations locally is generally a more secure alternative and there exists several libraries that can assist with this.

Forging the JSON object from the previous example would return the following hex string:

62140084605d2c8129e1d1365c14c30a0801e629c0d172790d82e3392b9b7c3008000079475e5c9217a4dd417179846f7a7b8529c895dec60af3c304e8529502c0aad701014228bd78294ca6ecff55908360b79dca4e7cf0af0000

Parsing

With parsing, we do the reverse and decode it from the binary repressentation to a JSON object. If we append a valid signature to the previous hex string:

62140084605d2c8129e1d1365c14c30a0801e629c0d172790d82e3392b9b7c3008000079475e5c9217a4dd417179846f7a7b8529c895dec60af3c304e8529502c0aad701014228bd78294ca6ecff55908360b79dca4e7cf0af0000cb0c076326588d8b5abee99acde9d23cacd929bf0e872902fbbc3eece3d54665a4ffc26587a2bbaa2dc570ea18d677d1df87679325f757268f0f50cc4f0f2e03

We would get the following JSON object after parsing it:

{
    "branch": "BLTUcKtBkLmQGRoXjiLEXcZHS9wR5Mgcq9sZkxU3DdLMVwy2wMu",
    "contents":
        [
            {
                "kind": "transaction",
                "source": "tz1WhHx7DMH8cKyXe5dv9cDy5wzFJX2wfTPB",
                "fee": "1350",
                "counter": "74227",
                "gas_limit": "10600",
                "storage_limit": "277",
                "amount": "3528000",
                "destination": "KT1Ecay6hLAsGmVSaRawzF1iNt8beuk1djDF"
            }
        ],
    "signature": "sigpZ2TFhHt2vUKBbvW83XQjkvrA744c8Foo78bu8Y252uMLEUSZ7VgK8mergVdHqtgLYtGDLoZzfjr1CZ1jJzKapGF91mEj"
}