# LibTransaction

The `LibTransaction` library provides functions for encoding and decoding a `Transaction` struct into a byte array.&#x20;

```solidity
struct Transaction {
    DataTransferType dataTransferType;
    BridgeType bridgeType;
    uint16 recipientNetworkId;
    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    bytes32 recipientAggregatorAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
    uint64 tokenSequence;
}
```

<table><thead><tr><th width="311.3333333333333">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>dataTransferType
</code></pre></td><td><pre><code>DataTransferType
</code></pre></td><td><p><code>DataTransferType</code> has two named values: <code>Wormhole</code> and <code>LayerZero</code>.</p><p>Each named value is assigned an implicit integer value, starting at 0 for the first value and incrementing by 1 for each subsequent value. In this case, <code>Wormhole</code> is assigned the value 0, and <code>LayerZero</code> is assigned the value 1.</p></td></tr><tr><td><pre><code>bridgeType
</code></pre></td><td><pre><code>BridgeType
</code></pre></td><td><p><code>BridgeType</code> has two named values: <code>Wormhole</code> and <code>Stargate</code>.</p><p>Each named value is assigned an implicit integer value, starting at 0 for the first value and incrementing by 1 for each subsequent value. In this case, <code>Wormhole</code> is assigned the value 0, and <code>Stargate</code> is assigned the value 1.</p></td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">recipientNetworkId
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16
</code></pre></td><td>the network id of the recipient chain.</td></tr><tr><td><pre><code>fromAssetAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>the address of the source asset address that will get swapped. Example: <code>0x0000000000000000000000007b155e039f60ad89b3b3761a513238dfeebd8ab1</code></td></tr><tr><td><pre><code>toAssetAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>the address of the destination asset address that will be received after swapping.<br>Example: <br><code>0x0000000000000000000000003b981e413aedcd075d96a8f28d2aaff9b15f4f01</code></td></tr><tr><td><pre><code>toAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>the address of the recipient. <br>Example: <code>0x000000000000000000000000EE2249f8E5c4E84882eBA16DC991F3Fd4404C955</code></td></tr><tr><td><pre><code>recipientAggregatorAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>the address of the aggregator at the destionation address. </td></tr><tr><td><pre><code>amountOutMin
</code></pre></td><td><pre><code>uint256
</code></pre></td><td>the minimum swapped amount that is acceptable by the user. Example: <code>100000000000000000</code></td></tr><tr><td><pre><code>swapOutGasFee
</code></pre></td><td><pre><code>uint256
</code></pre></td><td>the gas fee that the user can pay for the swapping. <br>Example: <code>100000</code></td></tr><tr><td><pre><code>tokenSequence
</code></pre></td><td><pre><code>uint64
</code></pre></td><td>the sequence we receive while transferring the tokens over the bridge. </td></tr></tbody></table>

<pre class="language-solidity"><code class="lang-solidity"><strong>struct TransactionValidation {
</strong>    bytes32 fromAssetAddress;
    bytes32 toAssetAddress;
    bytes32 toAddress;
    uint256 amountOutMin;
    uint256 swapOutGasFee;
}
</code></pre>

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>fromAssetAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>This field is of type <code>bytes32</code> and represents the address of the asset being transferred from. The address is typically encoded as a 32-byte value.</td></tr><tr><td><pre><code>toAssetAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>This field is of type <code>bytes32</code> and represents the address of the asset being transferred to. Similar to <code>fromAssetAddress</code>, it is encoded as a 32-byte value.</td></tr><tr><td><pre><code>toAddress
</code></pre></td><td><pre><code>bytes32
</code></pre></td><td>This field is of type <code>bytes32</code> and represents the destination address of the transfer. It is also encoded as a 32-byte value.</td></tr><tr><td><pre><code>amountOutMin
</code></pre></td><td><pre><code>uint256
</code></pre></td><td>This field is of type <code>uint256</code> and represents the minimum amount of the transferred asset that should be received. It defines a threshold for the expected output amount.</td></tr><tr><td><pre><code>swapOutGasFee
</code></pre></td><td><pre><code>uint256
</code></pre></td><td>This field is of type <code>uint256</code> and represents the gas fee associated with the swap or transfer operation. It specifies the amount of gas required for completing the transaction.</td></tr></tbody></table>

### encode()&#x20;

The `encode` function takes a `Transaction` struct and converts it into a byte array.&#x20;

**Input**&#x20;

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-solidity"><code class="lang-solidity">transaction
</code></pre></td><td><pre class="language-solidity"><code class="lang-solidity">Transaction
</code></pre></td><td>the transaction struct to perform the encoding.</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field </th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-solidity"><code class="lang-solidity">transactionPayload
</code></pre></td><td><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>returns the encoded data in the form of bytes.</td></tr></tbody></table>

### decode()

The `decode` function takes a byte array and converts it back into a `Transaction` struct.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-solidity"><code class="lang-solidity">transactionPayload
</code></pre></td><td><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>the payload in bytes that needs to be decoded</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-solidity"><code class="lang-solidity">transaction
</code></pre></td><td><pre class="language-solidity"><code class="lang-solidity">Transaction
</code></pre></td><td>returns the Transaction struct after the decoding is completed.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fly.trade/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/bridge/libtransaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
