> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fibrous.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute

> Execute a swap through Fibrous liquidity pools

## Endpoint

<CodeGroup>
  ```bash theme={null}
  https://api.fibrous.finance/hyperevm/execute
  ```
</CodeGroup>

Execute a token swap using the optimal route previously found through the route endpoint. This endpoint handles the actual transaction execution and ensures the swap is performed with the best possible outcome.

## Request Body Parameters

<ParamField body="route" type="RouteResponse" required>
  The route object returned from the `/hyperevm/route` endpoint. This contains all necessary information about the swap path and expected outcomes.
</ParamField>

<ParamField body="slippage" default="0.5" type="number" required>
  Maximum acceptable slippage in percentage (0.1 to 100). Example: `0.5` for 0.5% slippage tolerance
</ParamField>

<ParamField body="destination" type="string" required>
  Unix timestamp (in seconds) after which the transaction will revert. Defaults to 20 minutes from the current time if not specified.
</ParamField>

## Response

<ResponseField name="route" type="object">
  The executed route details.

  <Expandable>
    <ResponseField name="amount_in" type="string">
      The amount of input tokens in wei format.
    </ResponseField>

    <ResponseField name="amount_out" type="string">
      The amount of output tokens in wei format.
    </ResponseField>

    <ResponseField name="min_received" type="string">
      The minimum amount of output token.
    </ResponseField>

    <ResponseField name="destination" type="string">
      The destination address for the swap.
    </ResponseField>

    <ResponseField name="swap_type" type="number">
      The type of swap.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="swap_parameters" type="object[]">
  Swap parameters for every hop in the route.

  <Expandable>
    <ResponseField name="token_in" type="string">
      The token in address.
    </ResponseField>

    <ResponseField name="token_out" type="string">
      The token out address.
    </ResponseField>

    <ResponseField name="rate" type="string">
      The rate of the swap.
    </ResponseField>

    <ResponseField name="protocol_id" type="string">
      The protocol id of the swap.
    </ResponseField>

    <ResponseField name="pool_address" type="string">
      The pool address of the swap.
    </ResponseField>

    <ResponseField name="swap_type" type="number">
      The type of swap.
    </ResponseField>

    <ResponseField name="extra_data" type="string">
      The extra data of the swap.
    </ResponseField>
  </Expandable>
</ResponseField>

## Error Responses

### Route Expired

```json theme={null}
{
  "success": false,
  "error": "Route expired",
  "details": "The provided route has expired. Please fetch a new route."
}
```

### Slippage Exceeded

```json theme={null}
{
  "success": false,
  "error": "Slippage exceeded",
  "details": "The swap would result in more slippage than allowed"
}
```

### Insufficient Balance

```json theme={null}
{
  "success": false,
  "error": "Insufficient balance",
  "details": "Wallet does not have enough tokens for the swap"
}
```

### Invalid Deadline

```json theme={null}
{
  "success": false,
  "error": "Invalid deadline",
  "details": "Deadline must be a future timestamp"
}
```

<RequestExample>
  ```bash cURL theme={null}
  curl --location 'https://api.fibrous.finance/hyperevm/execute' \
  --header 'Content-Type: application/json' \
  --data '{
      "route":{
      "success": true,
      "routeSwapType": 0,
      "inputToken": {
          "name": "Wrapped HYPE",
          "address": "0x5555555555555555555555555555555555555555",
          "decimals": 18,
          "price": "55.16"
      },
      "inputAmount": "10000000000000000000",
      "outputToken": {
          "name": "USD₮0",
          "address": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
          "decimals": 6,
          "price": "1.001"
      },
      "outputAmount": "551266196",
      "time": 0.369,
      "estimatedGasUsed": "44164800000000",
      "estimatedGasUsedInUsd": 0.00487137744,
      "route": [
          {
              "percent": "100%",
              "swaps": [
                  [
                      {
                          "protocol": 13,
                          "poolName": "hybraFinanceV3",
                          "poolAddress": "0x5a716e045421b0977ca5bfb4f3394139c6a069bc",
                          "fromTokenAddress": "0x5555555555555555555555555555555555555555",
                          "toTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                          "percent": "100.00%",
                          "extraData": {
                              "fee": 25
                          }
                      }
                  ],
                  [
                      {
                          "protocol": 18,
                          "poolName": "kittenSwapAlgebraV4",
                          "poolAddress": "0x3cf44ef1500c1d559c8e81dffd6baeb0966b2712",
                          "fromTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                          "toTokenAddress": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
                          "percent": "99.00%",
                          "extraData": null
                      },
                      {
                          "protocol": 15,
                          "poolName": "gLiquidV3",
                          "poolAddress": "0x5e43a757ba769d4cd5fe568ae2429d4ae69e0ecf",
                          "fromTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                          "toTokenAddress": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
                          "percent": "1.00%",
                          "extraData": null
                      }
                  ]
              ]
          }
      ],
      "bestQuotesByProtocols": [],
      "initial": false
  },
  "slippage":0.1,
  "destination":"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
  }'
  ```

  ```python Python theme={null}
  import requests
  import json

  url = "https://api.fibrous.finance/hyperevm/execute"

  payload = json.dumps({
    "route": {
      "success": True,
      "routeSwapType": 0,
      "inputToken": {
        "name": "Wrapped HYPE",
        "address": "0x5555555555555555555555555555555555555555",
        "decimals": 18,
        "price": "55.16"
      },
      "inputAmount": "10000000000000000000",
      "outputToken": {
        "name": "USD₮0",
        "address": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
        "decimals": 6,
        "price": "1.001"
      },
      "outputAmount": "551266196",
      "time": 0.369,
      "estimatedGasUsed": "44164800000000",
      "estimatedGasUsedInUsd": 0.00487137744,
      "route": [
        {
          "percent": "100%",
          "swaps": [
            [
              {
                "protocol": 13,
                "poolName": "hybraFinanceV3",
                "poolAddress": "0x5a716e045421b0977ca5bfb4f3394139c6a069bc",
                "fromTokenAddress": "0x5555555555555555555555555555555555555555",
                "toTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                "percent": "100.00%",
                "extraData": {
                  "fee": 25
                }
              }
            ],
            [
              {
                "protocol": 18,
                "poolName": "kittenSwapAlgebraV4",
                "poolAddress": "0x3cf44ef1500c1d559c8e81dffd6baeb0966b2712",
                "fromTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                "toTokenAddress": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
                "percent": "99.00%",
                "extraData": None
              },
              {
                "protocol": 15,
                "poolName": "gLiquidV3",
                "poolAddress": "0x5e43a757ba769d4cd5fe568ae2429d4ae69e0ecf",
                "fromTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                "toTokenAddress": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
                "percent": "1.00%",
                "extraData": None
              }
            ]
          ]
        }
      ],
      "bestQuotesByProtocols": [],
      "initial": False
    },
    "slippage": 0.1,
    "destination": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
  })
  headers = {
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)

  ```

  ```javascript JavaScript theme={null}
  const axios = require('axios');
  let data = JSON.stringify({
    "route": {
      "success": true,
      "routeSwapType": 0,
      "inputToken": {
        "name": "Wrapped HYPE",
        "address": "0x5555555555555555555555555555555555555555",
        "decimals": 18,
        "price": "55.16"
      },
      "inputAmount": "10000000000000000000",
      "outputToken": {
        "name": "USD₮0",
        "address": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
        "decimals": 6,
        "price": "1.001"
      },
      "outputAmount": "551266196",
      "time": 0.369,
      "estimatedGasUsed": "44164800000000",
      "estimatedGasUsedInUsd": 0.00487137744,
      "route": [
        {
          "percent": "100%",
          "swaps": [
            [
              {
                "protocol": 13,
                "poolName": "hybraFinanceV3",
                "poolAddress": "0x5a716e045421b0977ca5bfb4f3394139c6a069bc",
                "fromTokenAddress": "0x5555555555555555555555555555555555555555",
                "toTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                "percent": "100.00%",
                "extraData": {
                  "fee": 25
                }
              }
            ],
            [
              {
                "protocol": 18,
                "poolName": "kittenSwapAlgebraV4",
                "poolAddress": "0x3cf44ef1500c1d559c8e81dffd6baeb0966b2712",
                "fromTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                "toTokenAddress": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
                "percent": "99.00%",
                "extraData": null
              },
              {
                "protocol": 15,
                "poolName": "gLiquidV3",
                "poolAddress": "0x5e43a757ba769d4cd5fe568ae2429d4ae69e0ecf",
                "fromTokenAddress": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
                "toTokenAddress": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
                "percent": "1.00%",
                "extraData": null
              }
            ]
          ]
        }
      ],
      "bestQuotesByProtocols": [],
      "initial": false
    },
    "slippage": 0.1,
    "destination": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
  });

  let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'https://api.fibrous.finance/hyperevm/execute',
    headers: { 
      'Content-Type': 'application/json'
    },
    data : data
  };

  axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
      "route": {
          "token_in": "0x5555555555555555555555555555555555555555",
          "token_out": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
          "amount_in": "10000000000000000000",
          "amount_out": "551266196",
          "min_received": "550714930",
          "destination": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
          "swap_type": 0
      },
      "swap_parameters": [
          {
              "token_in": "0x5555555555555555555555555555555555555555",
              "token_out": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
              "rate": "1000000",
              "protocol_id": "13",
              "pool_address": "0x5a716e045421b0977ca5bfb4f3394139c6a069bc",
              "swap_type": 0,
              "extra_data": "0x0000000000000000000000000000000000000000000000000000000000000019"
          },
          {
              "token_in": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
              "token_out": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
              "rate": "990000",
              "protocol_id": "18",
              "pool_address": "0x3cf44ef1500c1d559c8e81dffd6baeb0966b2712",
              "swap_type": 2,
              "extra_data": "0x0000000000000000000000000000000000000000000000000000000000000000"
          },
          {
              "token_in": "0xfd739d4e423301ce9385c1fb8850539d657c296d",
              "token_out": "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
              "rate": "10000",
              "protocol_id": "15",
              "pool_address": "0x5e43a757ba769d4cd5fe568ae2429d4ae69e0ecf",
              "swap_type": 2,
              "extra_data": "0x0000000000000000000000000000000000000000000000000000000000000000"
          }
      ]
  }
  ```
</ResponseExample>

## Best Practices

1. **Route Freshness**
   * Always use a fresh route from the `/hyperevm/route` endpoint
   * Routes can become stale due to market movements
   * Implement retry logic with fresh routes if execution fails
2. **Slippage Management**
   * Set appropriate slippage tolerance based on:
     * Token pair volatility
     * Trade size
     * Market conditions
   * Higher values increase success rate but may result in worse prices
   * Lower values ensure better prices but may cause more failed transactions
3. **Deadline Setting**
   * Set reasonable deadlines to prevent stale transactions
   * Consider network congestion when setting deadlines
   * Default of 20 minutes is suitable for most cases
4. **Gas Optimization**
   * Monitor `gasUsed` in responses to optimize future transactions
   * Consider using direct routes for major pairs
   * Bundle multiple swaps if possible

## See Also

* [Route Endpoint](/api-reference/hyperevm/endpoint/route) - Find the optimal route for your swap
* [Calldata Endpoint](/api-reference/hyperevm/endpoint/calldata) - Get raw transaction data
* [Gas Estimation](/api-reference/gas-estimation) - Understanding gas costs
