> For the complete documentation index, see [llms.txt](https://docs.fly.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fly.trade/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/data-transfer/libdatatransfer.md).

# LibDataTransfer

This is a Solidity smart contract library that provides functions related to data transfer between different blockchain networks or layers.&#x20;

### getOriginalPayload()

this function is responsible for extracting the original payload from the extended payload by slicing the `extendedPayload` from the 42nd byte to the end. It removes the extended part of the payload and returns the original payload.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">extendedPayload
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>Payload + extra information like which data transfer type has been used</td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>payload</td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>the original payload</td></tr></tbody></table>

### dataTransfer()

this function is responsible for executing data transfer operations based on the specified protocols. It increments the core sequence, creates a transfer key, generates the extended payload, and processes each protocol in `dataTransferInArgs.protocols`. Depending on the protocol's `dataTransferType`, either the Wormhole or LayerZero data transfer function is called. If an unrecognised `dataTransferType` is encountered, the function reverts with an error.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">dataTransferInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DataTransferInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct DataTransferInArgs {
    DataTransferInProtocol protocol;
    TransferKey transferKey;
    bytes payload;
}

</code></pre></td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">transferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">TransferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
</code></pre></td></tr></tbody></table>

### getPayload()

this function is responsible for obtaining the transfer key and payload based on the specified data transfer type. Depending on the `dataTransferType` in `dataTransferOutArgs`, either the Wormhole or LayerZero library functions are called to obtain the payload.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">dataTransferOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DataTransferOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct DataTransferOutArgs {
    DataTransferType dataTransferType;
    bytes payload;
}
</code></pre></td></tr></tbody></table>

**Output**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">transferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">TransferKey
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct TransferKey {
    uint16 networkId;
    bytes32 senderAddress;
    uint64 swapSequence;
}
</code></pre></td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">payload
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes
</code></pre></td><td>The data necessary for swapping.</td></tr></tbody></table>
