This guide provides a structured, step by step approach to fetch exchange rates for token pair using GlueX Exchange Rates API. It covers everything about fetching exchange rates, from basic requests to advanced implementation patterns for production applications

Prerequisites

Before you begin, ensure you have:
  • Basic understanding of REST API concepts
  • Access to a development environment with HTTP request capabilities
  • Understanding of blockchain token addresses and chain identifiers

Preparing the Request

The Exchange Rates API uses a flexible request structure that supports both single token lookups and batch operations

Request Body

  • domestic_token: The primary token address you want to price
  • domestic_blockchain: The blockchain where the domestic token resides
  • foreign_blockchain: The blockchain for the comparison token
  • foreign_token: The comparison token address
[
  {
    "domestic_token": "tokenA-address",
    "foreign_token": null,
    "domestic_blockchain": "blockchain_id_1",
    "foreign_blockchain": "blockchain_id_1"
  },
  {
    "domestic_token": "tokenB-address",
    "foreign_token": "tokenC-address",
    "domestic_blockchain": "blockchain_id_2",
    "foreign_blockchain": "blockchain_id_2"
  }
]

Making the Request

curl -X POST "https://exchange-rates.gluex.xyz" \
  -H "Content-Type: application/json" \
  -d '[{"domestic_token": "tokenA-address", "foreign_token": null, "domestic_blockchain": "blockchain_id_1", "foreign_blockchain": "blockchain_id_1"}, {"domestic_token": "tokenB-address", "foreign_token": "tokenC-address", "domestic_blockchain": "blockchain_id_2", "foreign_blockchain": "blockchain_id_2"}]'

Handling the Response

The response will contain a list of exchange rates for the requested token pairs
[
  {
    "domestic_token": "tokenA-address",
    "price": 0.00010741495276069063,
    "foreign_token": "blockchain_id_1_native-currency-address",
    "domestic_blockchain": "blockchain_id_1",
    "foreign_blockchain": "blockchain_id_1"
  },
  {
    "domestic_token": "tokenB-address",
    "price": 1.0013751780636744e-12,
    "foreign_token": "tokenC-address",
    "domestic_blockchain": "blockchain_id_2",
    "foreign_blockchain": "blockchain_id_2"
  }
]
You’re ready to integrate real time exchange rates into your app!