Skip to main content

Overview

The Swap Quoting endpoint provides swap quotes with optimized routing across multiple DEXs and liquidity sources. It returns the estimated output amount, slippage, and a serialized transaction ready to be signed.
Private Beta Access OnlyThis endpoint is not yet available to the general public. Please contact the Mobula team to request access.

Query Parameters

  • chainId (required) — The blockchain identifier (e.g., evm:1, solana, ethereum)
  • tokenIn (required) — Address of the token to swap from (use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native tokens)
  • tokenOut (required) — Address of the token to swap to (use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native tokens)
  • amount (required) — Amount of tokenIn to swap (in token’s base units)
  • walletAddress (required) — Wallet address that will execute the swap
  • slippage (optional) — Maximum acceptable slippage percentage (0-100). Default: 1
  • excludedProtocols (optional) — Comma-separated list of factory addresses to exclude from routing. Can be any factory address.
  • onlyProtocols (optional) — Comma-separated list of tradable pool types to restrict routing to (e.g., uniswap-v2, uniswap-v3, raydium-amm). Only valid tradable pool types will be considered; non-tradable types will be filtered out.
  • poolAddress (optional) — Specific pool address to use for the swap

Usage Examples

Basic Swap Quote

curl -X GET "https://api.mobula.io/api/2/swap/quoting?chainId=solana&tokenIn=So11111111111111111111111111111111111111112&tokenOut=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=1000000000&walletAddress=YourWalletAddress&slippage=1"

Swap with Excluded Protocols

curl -X GET "https://api.mobula.io/api/2/swap/quoting?chainId=ethereum&tokenIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&tokenOut=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&amount=1000000000000000000&walletAddress=0xYourWalletAddress&slippage=2&excludedProtocols=uniswap-v2,sushiswap"

Swap with Specific Pool Type

curl -X GET "https://api.mobula.io/api/2/swap/quoting?chainId=evm:1&tokenIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&tokenOut=0xdAC17F958D2ee523a2206206994597C13D831ec7&amount=500000000000000000&walletAddress=0xYourWalletAddress&onlyProtocols=uniswap-v3"

Response Format

Currently supports Solana blockchain. EVM chains support coming soon.

Solana Response

{
  "data": {
    "solana": {
      "transaction": {
        "serialized": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDMzMzMzMzMzMzMzMzMzMzMzMzMzMz...",
        "variant": "versioned"
      }
    },
    "estimatedAmountOut": "99500000",
    "estimatedSlippage": 0.5,
    "requestId": "123e4567-e89b-12d3-a456-426614174000"
  }
}

Response Fields

Data Object

For Solana:
  • solana (object, optional) — Solana transaction container
    • transaction (object) — Transaction details
      • serialized (string) — Base64 encoded serialized transaction
      • variant (enum: legacy | versioned) — Transaction variant
Common Fields:
  • estimatedAmountOut (string, optional) — Estimated output amount in tokenOut’s base units
  • estimatedSlippage (number, optional) — Estimated slippage percentage
  • requestId (string) — Unique identifier for tracking this request. Keep this ID and provide it to the Mobula team if you encounter any issues.

Error Field

  • error (string, optional) — Error message if the quote failed. If you receive an error, please report it to the Mobula team along with the requestId for faster resolution.

Example Responses

Successful Solana Swap Quote

{
  "data": {
    "solana": {
      "transaction": {
        "serialized": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDMzMzMzMzMzMzMzMzMzMzMzMzMzMz...",
        "variant": "versioned"
      }
    },
    "estimatedAmountOut": "99750000",
    "estimatedSlippage": 0.25,
    "requestId": "550e8400-e29b-41d4-a716-446655440000"
  }
}

Quote with Error

{
  "data": {
    "estimatedAmountOut": "0",
    "estimatedSlippage": 5.0,
    "requestId": "770e8400-e29b-41d4-a716-446655440002"
  },
  "error": "Insufficient liquidity for the requested swap amount"
}

Important Notes

  • Native Token Address: Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native tokens on EVM chains, and the corresponding native token address on Solana (So11111111111111111111111111111111111111112 for SOL)
  • Amount Format: Amounts should be provided in the token’s smallest unit (wei for ETH, lamports for SOL, etc.)
  • Blockchain Support: Currently supports Solana. EVM chains support coming soon.
  • Solana Transactions: Base64 encoded and ready to be deserialized, signed, and sent
  • Slippage: Higher slippage increases success rate but may result in worse execution prices
  • Request ID: Always keep the requestId from the response. In case of any issues or errors, provide this ID to the Mobula team for faster troubleshooting and resolution.
  • onlyProtocols Behavior: This parameter only restricts routing to a subset of tradable pool types. Non-tradable pool types will be automatically filtered out. You cannot extend beyond the base set of tradable protocols.
  • excludedProtocols Behavior: You can specify any factory address to exclude from routing, regardless of whether it’s tradable or not.

Next Steps

For Solana Transactions

After receiving a quote:
  1. Save the requestId for troubleshooting purposes
  2. Decode the base64 serialized transaction
  3. Deserialize based on the variant field (legacy or versioned)
  4. Sign it with your Solana wallet
  5. Send to the network using your preferred RPC
Example:
const { solana, requestId } = response.data;

// Save requestId for support
console.log('Request ID:', requestId);

const txBuffer = Buffer.from(solana.transaction.serialized, 'base64');

if (solana.transaction.variant === 'versioned') {
  const tx = VersionedTransaction.deserialize(txBuffer);
  tx.sign([wallet]);
  const signature = await connection.sendTransaction(tx);
  console.log('Transaction sent:', signature);
} else {
  const tx = Transaction.from(txBuffer);
  tx.partialSign(wallet);
  const signature = await connection.sendTransaction(tx);
  console.log('Transaction sent:', signature);
}

EVM Support

EVM chains support is coming soon. The API will support Ethereum, BSC, Polygon, and other EVM-compatible chains.

Use Cases

  • DEX Aggregation: Get the best swap rates across multiple DEXs
  • Trading Bots: Automated trading with optimal routing
  • DeFi Applications: Integrate swap functionality into your dApp
  • Price Comparison: Compare swap rates before execution