Skip to main content

Overview

Solana Swap Execution - Alpha ModeSwap execution on Solana is currently in alpha mode. The feature is functional but may have limitations. EVM chains are fully stable and production-ready. Please report any Solana-related issues to the Mobula team.
This guide walks you through the complete process of executing a token swap using Mobula’s Swap API. You’ll learn how to:
  1. Get an optimized swap quote
  2. Sign the transaction with your wallet
  3. Broadcast the transaction to the blockchain
  4. Monitor the transaction status
The Mobula Swap API provides optimal routing across multiple DEXs and supports both EVM chains and Solana.

Supported EVM Chains

All EVM swaps are executed through MobulaRouter, a smart contract deployed on:
ChainChain IDNative Token
Ethereumevm:1ETH
Optimismevm:10ETH
BNB Chainevm:56BNB
Polygonevm:137MATIC
Baseevm:8453ETH
Arbitrumevm:42161ETH
Avalancheevm:43114AVAX
Robinhood Chainevm:4663ETH
MobulaRouter automatically routes to the best available aggregator for optimal pricing across all DEX liquidity on each chain.

Prerequisites

  • Node.js 18+ installed
  • A Mobula API key (get one at admin.mobula.io)
  • Basic knowledge of TypeScript/JavaScript
  • A wallet with funds on the blockchain you want to swap on

Installation

First, install the required dependencies:

Complete Swap Flow

Step 1: Get a Swap Quote

The first step is to request a swap quote. The API will return the estimated output amount and a serialized transaction ready to be signed.

Step 2: Sign the Transaction

Once you have the quote, you need to sign the transaction with your wallet. The process differs between Solana and EVM chains.

Solana Transaction Signing

EVM Transaction Signing

Step 3: Send the Signed Transaction

After signing, broadcast the transaction to the blockchain.

Step 4: Monitor Transaction Status

After broadcasting, monitor the transaction on the blockchain.

Complete Examples

Example 1: Swap SOL to USDC on Solana

Example 2: Swap ETH to USDC on Ethereum

Example 3: Advanced Swap with Protocol Restrictions

Error Handling Best Practices

Important Notes

Token Addresses

  • EVM native tokens: Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native tokens on any EVM chain (ETH, BNB, MATIC, AVAX)
  • Solana native: Use So11111111111111111111111111111111111111112 for SOL
  • Token amounts: Always use the smallest unit (wei for EVM, lamports for Solana)

EVM Chains

All EVM swap transactions go through MobulaRouter. The response provides a ready-to-sign transaction in the evm.transaction field:
For native token swaps (ETH, BNB, MATIC, AVAX), use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE as tokenIn. The API will set the correct value field in the transaction. For ERC-20 token swaps, you must first approve the MobulaRouter contract to spend your tokens. The router address is returned in evm.transaction.to.

Amount Conversion

Protocol Filtering

  • onlyProtocols: Restricts routing to specific tradable protocols. Only valid tradable pool types will be considered.
  • excludedProtocols: Excludes specific factory addresses from routing.

Slippage Recommendations

  • Stablecoins: 0.1% - 0.5%
  • Major tokens: 0.5% - 1%
  • Low liquidity tokens: 2% - 5%
  • Memecoins: 5% - 10%
Higher slippage increases success rate but may result in worse execution prices.

Troubleshooting

Common Issues

  1. “Slippage too high”
    • Increase slippage tolerance
    • Reduce swap amount
    • Wait for better market conditions
  2. “No route found”
    • Check token addresses are correct
    • Verify tokens have liquidity on the chain
    • Try without protocol restrictions
  3. “Transaction simulation failed”
    • Insufficient balance (including gas fees)
    • Token approval may be needed (for non-native tokens)
    • Slippage tolerance too low
  4. Transaction not confirming
    • Network congestion (especially on Ethereum)
    • Gas price too low (EVM chains)
    • Check blockchain explorer with transaction hash

Next Steps

Support

Need help? Join our community: