Skip to main content
Welcome to the GlueX Quickstart Guides! Whether you’re a developer integrating GlueX into your platform or a partner looking to utilize our framework or embed our widget, these guides will help you get up and running quickly and efficiently GlueX provides a comprehensive suite of tools to simplify complex DeFi interactions:
  • Router: Bridge, swap, lend, stake and compose multistep flows in one call
  • Exchange Rates: Fetch real time pricing across chains
  • Yield: Discover and optimize yield values
  • Debt: Borrow, repay and manage debt positions in a single transaction
  • Widget: Prebuilt UI components for a secure and smooth UX
  • Swidge (Coming Soon)
  • Solve (Coming Soon)

Router

The Route API is a powerful and flexible automated pathfinding engine designed for developers to implement efficient onchain interaction logic and calculate optimal path between any two DeFi positions. Whether you’re swapping tokens, entering positions, adding liquidity or moving assets, the API provides everything needed for handling the complex routing logic automatically

Getting Your First Router Quote

The first step in using the GlueX Router API is to generate a quote for a desired DeFi operation. This can be achieved by sending a POST request to the /v1/quote endpoint. It’s recommended to start with the below example request and then explore more customization options in the Router API Reference

Sample Request

The first step in using the GlueX Router API to generate a quote. This can be achieved by sending a POST request to the /v1/quote endpoint. It is recommended to start with the below example request and apply more customization from (here)[/docs/router/quote]
curl 'https://router.gluex.xyz/v1/quote' \
-H 'content-type: application/json' \
-H 'x-api-key: <api-key>' \
--data-raw '{
  "inputToken": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  "outputToken": "0xdac17f958d2ee523a2206206994597c13d831ec7",
  "inputAmount": "100000000",
  "userAddress": "0x2...A9D",
  "outputReceiver": "0x2...A9D",
  "chainID": "ethereum",
  "uniquePID": "<unique-pid>",
  "isPermit2": false
}'

Sample Response

{
  "statusCode": 200,
  "result": {
    "inputToken": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "outputToken": "0xdac17f958d2ee523a2206206994597c13d831ec7",
    "feeToken": "0xdac17f958d2ee523a2206206994597c13d831ec7",
    "inputSender": "0x2...a9d",
    "outputReceiver": "0x2...a9d",
    "inputAmount": "100000000",
    "outputAmount": "110023345",
    "partnerFee": "0",
    "routingFee": "0",
    "effectiveInputAmount": "100000000",
    "effectiveOutputAmount": "110023345",
    "minOutputAmount": "107822878",
    "liquidityModules": [
      "uniswap_v2",
      "uniswap_v3",
      "sushiswap",
      "solidly_v3"
    ],
    "router": "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7",
    "calldata": "0xb8039e98...00000000000",
    "isNativeTokenInput": false,
    "value": "0",
    "revert": true,
    "computationUnits": 2000000,
    "blockNumber": 22803966,
    "lowBalance": true
  }
}

How to Use

Once you have the /quote response, you can use any web3 library (eg: ethers.js, web3.js, web3.py) to build, sign and send the transaction. The key fields you’ll need are:
  • calldata: ABI encoded function call for the router
  • value: Native token amount to attach (if input is a native token)
  • computationUnits: Simulated gas estimate (recommended - gasLimit = computationUnits × 1.3)
Simply construct your transaction object with those fields, sign it with your EOA’s private key and broadcast it

Learn More

Examples

With Router’s token swap API, you can swap any token A → token B on any supported blockchain in just one call. Instead of dealing with multiple steps like approvals, liquidity sourcing and slippage calculations, Router takes care of everything under the hood, letting you focus on what matters - receiving your desired token directly in your wallet

Why use GlueX for token swaps?

Traditionally, swapping tokens on a blockchain involves:
  1. Finding liquidity pools across decentralized exchanges (DEXs)
  2. Checking prices and slippage tolerance to avoid bad execution
  3. Manually approving tokens so they can be spent by a smart contract
  4. Building and broadcasting the transaction with correct gas settings
  5. Tracking the transaction until it confirms
Router simplifies all of this into a single, streamlined API call. When you specify:
  • The input token (what you’re swapping from)
  • The output token (what you’re receiving)
  • The amount
  • Your wallet address
Router will:
  • Aggregate liquidity across multiple sources to find the best route
  • Handle token approvals automatically
  • Execute the transaction in one step
  • Send the output tokens directly to your wallet (or any another specified address)
This guarantees a faster, more efficient and user friendly swap experience

Example: Swap USDT → WBTC on Ethereum

Here’s how you can swap 100 USDT into WBTC on Ethereum in a single API request:
POST /v1/quote
{
  "inputToken": "0xdac17f958d2ee523a2206206994597c13d831ec7",     // USDT contract address
  "outputToken": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",    // WBTC contract address
  "inputAmount": "100000000",                                     // 100 USDT (6 decimals)
  "userAddress": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91",    // Wallet executing the swap
  "outputReceiver": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91", // Wallet receiving WBTC
  "chainID": "ethereum",                                          // Target blockchain
  "uniquePID": "<your-unique-pid>"                                // Integrator ID
}
Here’s a real USDT → WBTC one call swap - 0x91c969f626d80c273008627d1a9d47b5f4600d9584ee045f0fdd57a080320dce
With Router’s vault entry flow, you can deposit into yield vaults (like Yearn, Aave, etc.) in just one transaction No matter if you already hold the vault’s underlying asset or need to swap into it first, Router handles all the required steps automatically, saving you from manual approvals and multiple transactions

Why use GlueX for vault deposits?

Normally, entering a vault requires several steps:
  1. Acquire the correct deposit token (swap into the asset the vault accepts)
  2. Approve the vault contract to spend your tokens
  3. Deposit the tokens into the vault
  4. Wait for confirmation before receiving vault shares in your wallet
Router simplifies this process into a single API call. You just specify:
  • The input token (what you’re starting with)
  • The vault token (the token you’ll receive, eg: yvUSDC)
  • The amount
  • Your wallet address
Router will:
  • Swap into the correct deposit asset if needed
  • Approve the vault contract automatically
  • Deposit the tokens on your behalf
  • Send the vault shares (yvTokens) directly to your wallet (or any another specified address)
This makes vault entry seamless, gas efficient and user friendly

Example: Example: Deposit WBTC → MEVCapital USDC Vault

Here’s how you can deposit WBTC directly into the MEVCapital USDC Vault in one step:
POST /v1/quote
{
  "inputToken": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",     // WBTC contract address
  "outputToken": "0xd63070114470f685b75b74d60eec7c1113d33a3d",    // MEVCapital USDC Vault token address
  "inputAmount": "50000",                                         // Amount of WBTC in satoshis (5 decimals)
  "userAddress": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91",    // Wallet executing the deposit
  "outputReceiver": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91", // Wallet receiving yvUSDC
  "chainID": "ethereum",                                          // Target blockchain
  "uniquePID": "<your-unique-pid>"                                // Integrator ID
}
Here’s a real WBTC → MEVCapital USDC vault deposit transaction - 0xe608be4745380168d4b882f012cb37b0282ff0ff96749ad579747143a4693c6b
With Router’s lending flow, you can supply assets to lending protocols (like Aave, Compound, etc) and receive interest-bearing tokens (aTokens, cTokens, etc) in one unified action. Whether you already hold the protocol’s required asset or need to swap into it first, Router automates the entire process

Why use GlueX for Lending?

Normally, lending assets requires several manual steps:
  1. Swap into the correct deposit token (eg: swap USDC into WETH if the protocol requires WETH)
  2. Approve the lending protocol contract to spend your tokens
  3. Call the protocol’s deposit method to supply liquidity
  4. Receive the corresponding aToken/cToken representing your deposit
Router compresses this into a single call. You only need to specify:
  • The input token (what you’re starting with)
  • The deposit token you want to receive (eg: aWETH)
  • The amount
  • Your wallet address
Router will:
  • Swap into the correct asset if needed
  • Handle approvals automatically
  • Supply liquidity to the protocol
  • Deliver the interest bearing token directly to your wallet (or any another specified address)

Example: Lend USDC → Receive aWETH

Here’s how to lend 50 USDC and receive aWETH in a single API request:
  POST /v1/quote
  {
    "inputToken": "0xa0b86991c6218b36c1d19D4a2e9eb0ce3606eb48",     // USDC contract address
    "outputToken": "0x4d5f47fa6a74757f35c14fd3a6ef8e3c9bc514e8",    // aWETH contract address (Aave)
    "inputAmount": "50000000",                                      // 50 USDC (6 decimals)
    "userAddress": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91",    // Wallet executing the deposit
    "outputReceiver": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91", // Wallet receiving yvUSDC
    "chainID": "ethereum",                                          // Target blockchain
    "uniquePID": "<your-unique-pid>"                                // Integrator ID
  }
Here’s a real USDC → Receive aWETH lending transaction - 0x37cdcdf63b962f3a945c37436da2965c12f590cc340eee72dde1187aa9ae0a40
With Router’s staking flow, you can stake any token into a staking protocol (such as Lido, Swell, Rocket Pool, etc) and receive the staked token in a single call. Whether you already hold the staking asset or need to swap into it first, Router automates the full lifecycle - from swap, to staking - in one gas optimized transaction

Why Use Router for Staking?

Normally, staking involves multiple steps:
  1. Swap into the staking asset if you don’t already hold it
  2. Approve the staking contract to spend your tokens
  3. Send the stake transaction to the protocol
  4. Receive your staked token in return
Router combines these steps into one unified API call. You just specify:
  • The input token (what you’re staking with)
  • The staked token you want to receive
  • The amount
  • Your wallet address
Router will:
  • Swap if required into the correct staking asset
  • Approve the staking contract
  • Stake on your behalf
  • Deliver the staked token directly to your wallet

Example: Stake DAI → swETH

Here’s how to stake DAIswETH in one call using Router:
  POST /v1/quote
  {
    "inputToken": "0x6b175474e89094c44da98b954eedeac495271d0f",                      // DAI contract address
    "outputToken": "0xf951e335afb289353dc249e82926178eac7ded78",                     // swETH contract address
    "inputAmount": "506591370407006083313",                                           // Amount of DAI (18 decimals)
    "userAddress": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91",                                       // Wallet executing the stake
    "outputReceiver": "0xb06B08B7bDb9C21c3a95F6688994172C25A54d91                   "                  , // Wallet receiving swETH
    "chainID": "ethereum",                                                          // Target blockchain
    "uniquePID": "866a61811189692e8eccae5d2759724a812fa6f8703ebffe90c29dc1f886bbc1" // Unique request ID
  }
Here’s a real USDC → Receive DAI** into swETH lending transaction - 0x37cdcdf63b962f3a945c37436da2965c12f590cc340eee72dde1187aa9ae0a40
COMING SOON…

Exchange Rate

The Exchange Rates API provides an easy to use, scalable solution for retrieving on-chain exchange rates between any two token pairs across multiple supported blockchains. Whether you’re building a DeFi app, wallet or trading platform, you can fetch realtime, accurate rates in a single batch call

Sample Request

The first step in using the GlueX Exchange Rates API to fetch the price of a token pair. This can be achieved by sending a POST request to the root / endpoint. It is recommended to start with the below example request and apply more customization from (here)[/api-reference/exchange-rate-api/post-price]
Each call can batch upto 25 pairs per request
curl 'https://exchange-rates.gluex.xyz/' \
  -H 'content-type: application/json' \
  --data-raw '[{
    "domestic_blockchain": "ethereum",
    "domestic_token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "foreign_blockchain": "ethereum",
    "foreign_token": "0xdac17f958d2ee523a2206206994597c13d831ec7"
  }]'

Sample Request

[
  {
    "domestic_token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "foreign_token": "0xdac17f958d2ee523a2206206994597c13d831ec7",
    "domestic_blockchain": "ethereum",
    "foreign_blockchain": "ethereum",
    "price": "0.9991396602323227"
  }
]

How to Use

  • Parse the JSON: Iterate over the array to extract price for each token pair
  • Batching: Request up to 25 pairs at once to minimize round trips
  • No Auth Needed: Public access by default, supply an API key header for higher rate limits when available

Learn More

Examples

COMING SOON…

Widget

The GlueX Widget offers a plug and play UI for embedding full featured DeFi operations like routing, swap, bridge, stake, lend and more into your applicaation with minimal code and maximum customization

Installation

Install the core packages (using your preferred package manager):
npm install wagmi @tanstack/react-query @gluex/widget @gluex/sdk

Sample Integration

Embed the widget in your React (or compatible) app with just a few lines:
import { GlueXWidget, WidgetConfiguration } from "@gluex/widget";

const config: Partial<WidgetConfiguration> = {
  apiKey: environment.GLUEX_API_KEY,
  integrator: environment.INTEGRATOR_ID,
};

export const DeFiWidget = () => {
  return <GlueXWidget config={config} />;
};

Learn More