> For the complete documentation index, see [llms.txt](https://ton-play-1.gitbook.io/ton-play-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ton-play-1.gitbook.io/ton-play-1/digital-assets-api/merging-api.md).

# Merging API

Merging objects:

**MergeRootContract (MRC)**

* deployed by the game, the owner is a game
* serve output data (results of merge)
* deploy MergeInventory contracts

**MergeInventoryContract (MIC)**

* deployed by MergeRootContract for special user
* serve input data (what will be merged)

**Main flow:** ***merge two\*\*\*\* ****`sft1`**** ****into one**** \*\*\*\*`sft2`***

* The game decides which ft tokens (and what amount) will produce some other ft tokens in other amounts. This information has to be stored in the web2 backend.
* Based on merge options (merge grid, output options from the previous point) **game deploys MRC.**
* The game must send all possible merge outputs to MRC.
* According to the initial game merging grid, the user wants to merge two `sft1` into one `sft2`.  The user **receives a link** to deploy MIC to start merging.
* When the user signs the link, MIC will be deployed. For this special user, MIC creates a special merge request.
* The user receives a special transfer link for sending two `sft1` to MIC and signs it.
* When MIC gets two `sft1`, it will send an event to MIC that checks what the user should get for this change and send it to the user (1 `sft2`)

## Public API

{% hint style="success" %}
**API Key** is required for all Public API requests&#x20;
{% endhint %}

## Generate deep link to deploy MRC

<mark style="color:green;">`POST`</mark> `https://external.api.tonplay.io/x/tondata/v1/merge/deploy/root`

#### Request Body

| Name     | Type   | Description |
| -------- | ------ | ----------- |
| owner    | String |             |
| address  |        |             |
| quantity | String |             |

{% tabs %}
{% tab title="200: OK " %}
{% code overflow="wrap" %}

```javascript
{
   https://app.tonkeeper.com/v1/txrequest-inline/eyJ2ZXJzaW9uIjoiMCIsImJvZHkiOnsidHlwZSI6InNpZ24tcmF3LXBheWxvYWQiLCJleHBpcmVzX3NlYyI6IjE2NzgxODI3NzUiLCJwYXJhbXMiOnsidmFsaWRfdW50aWwiOiIxNjc4MTgyNzc1IiwibWVzc2FnZXMiOlt7ImFkZHJlc3MiOiJFUURJWVAtejRETzBFZmpjU0hIU0JZZUdXTk9LRkZJVnBtT2cwU2U2TWR2LVRTb3YiLCJhbW91bnQiOiI1MDAwMDAwMCIsInBheWxvYWQiOiJ0ZTZjY2dFQkFnRUFRQUFCTFFBQUFBb0FBQUFBWkFiN1pnQUFBQUFBQUFBQUFBSEFBUUJIb0FSNWRKTDc0c2srN09PYnRPeW1MdzJhQnBpV2tHMThROWlINjhNc0RHMVJnQUF3In1dfSwicmVzcG9uc2Vfb3B0aW9ucyI6e319fQ
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

**Payload**

```jsx
{
    "owner": "kQC7ryRspjsMrdnuuA98uGyLMUVd_dDWjroYLBHoIz9ovl7e",
    "outputs": [
        [
            {
            "address": "EQDMZlnpaB2vckN9avhfMmNKcXh9CbVotmwsNE2kLMC8gZ_n",
            "quantity": 1
        }
        ]
    ]
}
```

Owner - the owner of MRC&#x20;

Outputs - list of possible outputs objects (merge results)

Output Object = {address - sft minter address, quantity - the amount of merge result sfts)

## Generate deeplink to deploy MIC

<mark style="color:green;">`POST`</mark> `https://external.api.tonplay.io/x/tondata/v1/merge/deploy/inventory`

#### Request Body

| Name              | Type   | Description                                          |
| ----------------- | ------ | ---------------------------------------------------- |
| mergeRootContract | String | address of parent merge root contract                |
| userAddress       |        | user that makes merge                                |
| outputId          | String | serial number of output result in output grid of MRC |
| address           | String | sft minter address                                   |
| quantity          | String | amount of merge result sfts                          |

{% tabs %}
{% tab title="200: OK " %}
{% code overflow="wrap" %}

```javascript
{
https://app.tonkeeper.com/v1/txrequest-inline/eyJ2ZXJzaW9uIjoiMCIsImJvZHkiOnsidHlwZSI6InNpZ24tcmF3LXBheWxvYWQiLCJleHBpcmVzX3NlYyI6IjE2NzgxODI3NzUiLCJwYXJhbXMiOnsidmFsaWRfdW50aWwiOiIxNjc4MTgyNzc1IiwibWVzc2FnZXMiOlt7ImFkZHJlc3MiOiJFUURJWVAtejRETzBFZmpjU0hIU0JZZUdXTk9LRkZJVnBtT2cwU2U2TWR2LVRTb3YiLCJhbW91bnQiOiI1MDAwMDAwMCIsInBheWxvYWQiOiJ0ZTZjY2dFQkFnRUFRQUFCTFFBQUFBb0FBQUFBWkFiN1pnQUFBQUFBQUFBQUFBSEFBUUJIb0FSNWRKTDc0c2srN09PYnRPeW1MdzJhQnBpV2tHMThROWlINjhNc0RHMVJnQUF3In1dfSwicmVzcG9uc2Vfb3B0aW9ucyI6e319fQ==>https://app.tonkeeper.com/v1/txrequest-inline/eyJ2ZXJzaW9uIjoiMCIsImJvZHkiOnsidHlwZSI6InNpZ24tcmF3LXBheWxvYWQiLCJleHBpcmVzX3NlYyI6IjE2NzgxODI3NzUiLCJwYXJhbXMiOnsidmFsaWRfdW50aWwiOiIxNjc4MTgyNzc1IiwibWVzc2FnZXMiOlt7ImFkZHJlc3MiOiJFUURJWVAtejRETzBFZmpjU0hIU0JZZUdXTk9LRkZJVnBtT2cwU2U2TWR2LVRTb3YiLCJhbW91bnQiOiI1MDAwMDAwMCIsInBheWxvYWQiOiJ0ZTZjY2dFQkFnRUFRQUFCTFFBQUFBb0FBQUFBWkFiN1pnQUFBQUFBQUFBQUFBSEFBUUJIb0FSNWRKTDc0c2srN09PYnRPeW1MdzJhQnBpV2tHMThROWlINjhNc0RHMVJnQUF3In1dfSwicmVzcG9uc2Vfb3B0aW9ucyI6e319fQ
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

**Payload**

```jsx
{
    "mergeRootContract": "EQDIYP-z4DO0EfjcSHHSBYeGWNOKFFIVpmOg0Se6Mdv-TSov",
    "userAddress": "kQC7ryRspjsMrdnuuA98uGyLMUVd_dDWjroYLBHoIz9ovl7e",
    "outputId": 0,
    "inputData": [
        {
            "address": "EQBPkOleGxbukXSl4HAhpYPmuQs1t1nRkFq9OOFfd3GiBTE2",
            "quantity": 1
        }
    ]
}
```

mergeRootContract - address of parent merge root contract

userAddress - user that makes a merge

outputId - serial number of output result in output grid of MRC

inputData - list of input objects

Input Object = { address - sft minter address, quantity - the amount of merge result sfts)

## Generate a deeplink to transfer FT to MIC

<mark style="color:green;">`POST`</mark> `https://external.api.tonplay.io/x/tondata/v1/merge/transfer`

#### Request Body

| Name             | Type   | Description                                        |
| ---------------- | ------ | -------------------------------------------------- |
| inventoryAddress | String | MIC address                                        |
| userAddress      | String | user that makes a merge                            |
| minterAddress    | String | sft minter address                                 |
| transferData     | String | up to 4 different types of SFT that will be merged |

{% tabs %}
{% tab title="200: OK " %}
{% code overflow="wrap" %}

```javascript
{
https://app.tonkeeper.com/v1/txrequest-inline/eyJ2ZXJzaW9uIjoiMCIsImJvZHkiOnsidHlwZSI6InNpZ24tcmF3LXBheWxvYWQiLCJleHBpcmVzX3NlYyI6IjE2NzgxODI3NzUiLCJwYXJhbXMiOnsidmFsaWRfdW50aWwiOiIxNjc4MTgyNzc1IiwibWVzc2FnZXMiOlt7ImFkZHJlc3MiOiJFUURJWVAtejRETzBFZmpjU0hIU0JZZUdXTk9LRkZJVnBtT2cwU2U2TWR2LVRTb3YiLCJhbW91bnQiOiI1MDAwMDAwMCIsInBheWxvYWQiOiJ0ZTZjY2dFQkFnRUFRQUFCTFFBQUFBb0FBQUFBWkFiN1pnQUFBQUFBQUFBQUFBSEFBUUJIb0FSNWRKTDc0c2srN09PYnRPeW1MdzJhQnBpV2tHMThROWlINjhNc0RHMVJnQUF3In1dfSwicmVzcG9uc2Vfb3B0aW9ucyI6e319fQ
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

**Payload**

```jsx
{
    "inventoryAddress": "EQDkbP8EysDgf4i1QUHTqaYXNAvXTlUUwo6Zt5lZ1kFq5dc_",
    "userAddress": "kQC7ryRspjsMrdnuuA98uGyLMUVd_dDWjroYLBHoIz9ovl7e",
    "transferData": [
        {
            "address": "EQBPkOleGxbukXSl4HAhpYPmuQs1t1nRkFq9OOFfd3GiBTE2",
            "quantity": 1
        }
    ]
}
```

inventoryAddress - MIC address

userAddress - user that makes a merge

transferData - up to 4 different types of SFT that will be merged. \
Objects format: { address - sft minter address, quantity - the amount of merge result sfts)
