Skip to main content
POST
/
{network}
/
calldata
{
  "success": true,
  "route": {
    "inputToken": {},
    "outputToken": {},
    "inputAmount": "<string>",
    "outputAmount": "<string>",
    "time": 123,
    "route": [
      {}
    ]
  },
  "swap_parameters": [
    {
      "token_in": "<string>",
      "token_out": "<string>",
      "rate": "<string>",
      "protocol_id": "<string>",
      "pool_address": "<string>"
    }
  ],
  "calldata": "<string>",
  "to": "<string>",
  "value": "<string>"
}

Overview

The Calldata endpoint combines the functionality of both /route and /execute endpoints, providing an optimized way to get transaction calldata in a single API call. This is ideal for applications that want to minimize API calls and latency.

Supported Networks

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

Request Body Parameters

amount
string
required
The amount of input tokens in wei format.Example: "1000000000000000000" for 1 token with 18 decimals
tokenInAddress
string
required
The contract address of the input token.
tokenOutAddress
string
required
The contract address of the output token.
slippage
number
default:"0.5"
required
Maximum acceptable slippage in percentage (0.1 to 100).
destination
string
required
The destination address to receive the output tokens.
excludeProtocols
string[]
Array of protocol IDs to exclude from routing.
direct
boolean
default:"false"
If true, only direct swaps will be considered.

Response

This endpoint combines the route and execute responses:
success
boolean
Indicates if the route was successfully found
route
object
Complete route information (same as /route endpoint)
swap_parameters
object[]
Swap parameters for execution
calldata
string
The encoded transaction calldata ready for execution
to
string
The Fibrous Router contract address
value
string
The amount of native token to send with the transaction

Example Request

curl -X POST "https://api.fibrous.finance/base/calldata" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "1000000000000000000",
    "tokenInAddress": "0x0000000000000000000000000000000000000000",
    "tokenOutAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "slippage": 0.5,
    "destination": "0x1234567890123456789012345678901234567890"
  }'

Example Response

{
  "success": true,
  "route": {
    "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",
    "time": 0.495,
    "route": [
      {
        "percent": "51%",
        "swaps": [[...]]
      }
    ]
  },
  "swap_parameters": [
    {
      "token_in": "0x4200000000000000000000000000000000000006",
      "token_out": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
      "rate": "3165007379",
      "protocol_id": "9",
      "pool_address": "0x72ab388e2e2f6facef59e3c3fa2c4e29011c2d38"
    }
  ],
  "calldata": "0x...",
  "to": "0x274602a953847d807231d2370072f5f4e4594b44",
  "value": "1000000000000000000"
}

When to Use This Endpoint

Use Calldata

  • Single-step swap execution
  • Minimizing API calls
  • Reducing latency
  • Simple integrations

Use Route + Execute

  • Need to display route preview
  • User confirmation required
  • Complex routing logic
  • Custom route manipulation

Best Practices

  1. Token Approvals
    • Check token allowance before calling
    • Approve Fibrous Router to spend tokens
    • Not needed for native token swaps
  2. Transaction Execution
    • Use the exact to, calldata, and value from response
    • Set appropriate gas limit (use estimatedGas + buffer)
    • Monitor transaction status after submission
  3. Error Handling
    • Implement retry logic for failed requests
    • Handle insufficient liquidity gracefully
    • Validate addresses before calling

Complete Integration Example

import { ethers } from 'ethers';

async function executeSwap(provider, signer) {
  // 1. Get calldata
  const response = await fetch('https://api.fibrous.finance/base/calldata', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      amount: '1000000000000000000',
      tokenInAddress: '0x0000000000000000000000000000000000000000',
      tokenOutAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
      slippage: 0.5,
      destination: await signer.getAddress()
    })
  });
  
  const data = await response.json();
  
  // 2. Execute transaction
  const tx = await signer.sendTransaction({
    to: data.to,
    data: data.calldata,
    value: data.value,
    gasLimit: Math.floor(Number(data.estimatedGas) * 1.2) // 20% buffer
  });
  
  // 3. Wait for confirmation
  const receipt = await tx.wait();
  console.log('Swap completed:', receipt.transactionHash);
  
  return receipt;
}

Network-Specific Router Addresses

  • Base
  • HyperEVM
  • Scroll
  • Starknet
Router: 0x... (included in response)
Router addresses are always included in the API response. No need to hardcode them in your application.