> For the complete documentation index, see [llms.txt](https://docs.unizen.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unizen.io/gasless-trades/executing-the-trade.md).

# Executing the trade

#### **Gasless Trading Flow**

To perform a gasless trade, follow these steps using the gasless endpoints:

***

#### **1. Retrieve Typed Data**

**Endpoint**: `/v1/gasless/typed-data`\
Send a request with the trade details to this endpoint to retrieve the structured data required for the user to sign.

**Request:**

```json
{
    "transactionData": {
        "info": {
            "feeReceiver": "0xf4AA7a82B1d7f30Ca22D306c5eC429CF8AF160ef",
            "feePercent": 0,
            ...
        },
        "call": [
            {
                "targetExchange": "0x1F721E2E82F6676FCE4eA07A5958cF098D339e18",
                "targetExchangeID": "camelotv3",
                "sellToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
                "buyToken": "0x0000000000000000000000000000000000000000",
                "amountDelta": "1972679740777741",
                "amount": "6603531",
                "data": "0xac9650d80000...00000000000000000"
            }
        ],
        "version": "v2",
        "amountInAfterFee": "6603531",
        "amountInBeforeFee": "6623429",
        "fee": "19898"
    },
    "sender": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
    "chainId": 42161
}
```

**Response:**

```json
{
    "account": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
    "domain": {
        "name": "GasLessExecutor",
        "version": "1",
        "chainId": 42161,
        "verifyingContract": "0x9BCd841436ef4f85dacefB1aEc772aF71619024e"
    },
    "types": {
        "UnizenGasLessOrder": [
            {
                "name": "user",
                "type": "address"
            },
            ...
        ]
    },
    "primaryType": "UnizenGasLessOrder",
    "message": {
        "user": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "receiver": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "srcToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
        "dstToken": "0x0000000000000000000000000000000000000000",
        "amountIn": "6623429",
        "fee": "19898",
        "amountOutMin": "1972679740777741",
        "deadline": 1734963690,
        "tradeHash": "0x8748ade4edde06...e40b4dbc11fa47"
    }
}
```

***

#### **2. User Signs the Typed Data**

After receiving the `typedData` structure, the user must sign it using their wallet or signing tool (e.g., MetaMask, hardware wallets). This signature proves the user’s intent to perform the trade.

***

#### **3. Create the Order**

**Endpoint**: `/v1/gasless/create`\
Send the signature obtained from the user, along with the trade details, to this endpoint to create the order.

**Request:**

```json
{
    "chainFrom": 42161,
    "order": { // result of /v1/gasless/typed-data (message object)
        "user": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "receiver": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "srcToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
        "dstToken": "0x0000000000000000000000000000000000000000",
        "amountIn": "6623429",
        "fee": "19898",
        "amountOutMin": "1972679740777741",
        "deadline": 1734963690,
        "tradeHash": "0x8748ade4edde06...e40b4dbc11fa47"
    },
    "call": [ // call array from transactionData object of the quote 
        {
            "targetExchange": "0x1F721E2E82F6676FCE4eA07A5958cF098D339e18",
            "targetExchangeID": "camelotv3",
            "sellToken": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
            "buyToken": "0x0000000000000000000000000000000000000000",
            "amountDelta": "1972679740777741",
            "amount": "6603531",
            "data": "0xac9650d8000000000000000000000...00000000"
        }
    ],
    "permitData": { // if use Permit2
        "user": "0x2472d3EF4bF71af00c3dE490a5a53A99CbAC0791",
        "amount": "6623429",
        "deadline": 1734963223,
        "nonce": 569626219515420,
        "sign": "0xb43dbbcdcf610ff77fd17ab0630d5e85391086...04121f1b"
    },
    "signature": "0x2728c5bd1d666623533d899f6f6...7387b9e41c" // signature from step 2
}
```

**Response:**

```json
{"orderId":"561e1e2f-c32b-48c7-bb85-b9bc599d4d91"}
```

Once the order is created, it will be processed by our gasless trade processor. The system will cover the gas fees and execute the trade on behalf of the user.

***

#### **4. Cancel the Order (Optional)**

If the order has not been processed yet (this typically happens very quickly), it can be cancelled.

**Endpoint**: `/v1/gasless/cancel`

**Request:**

```json
{
  "orderId": "12345"
}
```

**Response:**

```json
{
  "success": true,
  "message": "Order cancelled successfully"
}
```

***

#### **Summary of Workflow**

1. **Call `/v1/gasless/typed-data`**: Retrieve the structured data for the user to sign.
2. **User Signs the Data**: Obtain a valid signature from the user.
3. **Call `/v1/gasless/create`**: Create the gasless order using the signature and trade details.
4. **(Optional) Cancel the Order**: If necessary, call `/v1/gasless/cancel` to cancel the order before it is processed.

***

#### **Key Notes**

* **Speed**: Orders are typically processed very quickly, minimizing the need for cancellations.
* **Security**: User signatures ensure the trade is authorized and secure.
* **Gasless Execution**: All gas fees are handled by the system, simplifying the process for the user.

For further details or troubleshooting, refer to the full API documentation or contact support. 🚀
