Skip to main content
POST
/
{network}
/
execute
{
  "route": {
    "amount_in": "<string>",
    "amount_out": "<string>",
    "min_received": "<string>",
    "destination": "<string>",
    "swap_type": 123
  },
  "swap_parameters": [
    {
      "token_in": "<string>",
      "token_out": "<string>",
      "rate": "<string>",
      "protocol_id": "<string>",
      "pool_address": "<string>",
      "swap_type": 123,
      "extra_data": "<string>"
    }
  ],
  "calldata": "<string>",
  "to": "<string>",
  "value": "<string>"
}

Overview

The Execute endpoint generates the necessary transaction data to execute a token swap using a previously obtained route. This endpoint is available across all supported networks.

Supported Networks

  • Base
  • HyperEVM
  • Scroll
  • Starknet
https://api.fibrous.finance/base/execute

Request Body Parameters

route
RouteResponse
required
The route object returned from the /route endpoint. This contains all necessary information about the swap path and expected outcomes.
slippage
number
default:"0.5"
required
Maximum acceptable slippage in percentage (0.1 to 100).Example: 0.5 for 0.5% slippage tolerance
destination
string
required
The destination address to receive the output tokens.
deadline
number
Unix timestamp (in seconds) after which the transaction will revert.Defaults to 20 minutes from the current time if not specified.

Response

route
object
The executed route details
swap_parameters
object[]
Swap parameters for every hop in the route
calldata
string
The encoded transaction calldata ready for execution
to
string
The Fibrous Router contract address to send the transaction to
value
string
The amount of native token to send with the transaction (for native token swaps)

Example Request

curl -X POST "https://api.fibrous.finance/base/execute" \
  -H "Content-Type: application/json" \
  -d '{
    "route": {
      "success": true,
      "inputToken": {
        "name": "Wrapped Ether",
        "address": "0x4200000000000000000000000000000000000006",
        "decimals": 18,
        "price": 3171.37
      },
      "outputToken": {
        "name": "USD Coin",
        "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
        "decimals": 6,
        "price": 0.99971
      },
      "inputAmount": "1000000000000000000",
      "outputAmount": "3165007379",
      "route": [...]
    },
    "slippage": 0.5,
    "destination": "0x1234567890123456789012345678901234567890"
  }'

Example Response

{
  "route": {
    "amount_in": "1000000000000000000",
    "amount_out": "3165007379",
    "min_received": "3149182360",
    "destination": "0x1234567890123456789012345678901234567890",
    "swap_type": 0
  },
  "swap_parameters": [
    {
      "token_in": "0x4200000000000000000000000000000000000006",
      "token_out": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
      "rate": "3165007379",
      "protocol_id": "9",
      "pool_address": "0x72ab388e2e2f6facef59e3c3fa2c4e29011c2d38",
      "swap_type": 0,
      "extra_data": "0x0064"
    }
  ],
  "calldata": "0x...",
  "to": "0x274602a953847d807231d2370072f5f4e4594b44",
  "value": "1000000000000000000"
}

Best Practices

  1. Route Freshness
    • Always use a fresh route from the /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
      • Available liquidity
      • 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 gas costs in responses to optimize future transactions
    • Consider using direct routes for major pairs
    • Batch multiple swaps when possible

Error Responses

Status Code: 400
{
  "error": "Route expired",
  "message": "The provided route is no longer valid. Please fetch a new route."
}
Solution: Fetch a new route and retry the execution.
Status Code: 400
{
  "error": "Insufficient liquidity",
  "message": "Not enough liquidity available for this swap amount."
}
Solution: Reduce the swap amount or try again later.
Status Code: 400
{
  "error": "Invalid slippage",
  "message": "Slippage must be between 0.1 and 100"
}
Solution: Adjust slippage to be within the valid range.

Network-Specific Notes

  • EVM Chains (Base, HyperEVM, Scroll)
  • Starknet
  • Use standard EVM transaction format
  • Native token swaps require sending value with transaction
  • Approve token spending before swap if not native token
  • Gas estimation included in response

Complete Swap Flow