Skip to main content

How Exchange Rates Work

Exchange rates work similarly for both offramps (stablecoin to fiat) and onramps (fiat to stablecoin):
1

Request rate

Query the rates endpoint with the source and destination currencies.
2

Display to user

Show the rate to your user in your UI before they initiate the transaction.

Retrieving Exchange Rates

Use these endpoints to get estimated conversion rates:

Offramp Rates (Stablecoin to Fiat)

Onramp Rates (Fiat to Stablecoin)

Response

string
Source currency code (e.g., usdc for stablecoin, usd, eur, brl for fiat).
string
Destination currency code (e.g., usd, eur, brl for fiat, usdc for stablecoin).
string
Estimated conversion rate from the source currency to the destination currency for the default transfer type. The rate is expressed as a string to preserve precision.
array
Array of conversion rates for different transfer types. Each object contains:

Usage Examples

Display Rate in UI

Retrieve rates to show users estimated conversion amounts before they create an offramp or onramp:

Calculate Estimated Amount

Use the rate to calculate estimated conversion amounts:

Key Concepts

Exchange rates from these endpoints are estimates for display purposes. The final conversion rate will be determined when you create the offramp or onramp request and may differ based on:
  • Current market conditions at transaction time
  • Fee calculations
  • Network fees
  • Quote expiration (quotes are valid for 10 minutes)
Always inform users that displayed rates are estimates and final amounts will be shown in the quote.
Conversion rates are returned as strings to preserve decimal precision. When performing calculations, always parse them to numbers.
Use parseFloat() or a decimal library (like decimal.js) for financial calculations to maintain accuracy.
Handle common error responses:
  • 401 Unauthorized: Invalid or missing API key
  • 404 Not Found: Unsupported currency pair
  • 500 Internal Server Error: Temporary service issue

Best Practices

Rate Caching: Cache exchange rates for 1-2 minutes to reduce API calls while keeping data reasonably fresh. Don’t cache longer than 5 minutes as rates can change.
  • Show estimates only: Always label displayed rates as “estimated” to set user expectations
  • Refresh on user action: Update rates when users change currency pairs
  • Handle rate changes gracefully: If a rate changes between display and transaction creation, the quote will show the actual rate
  • Validate currency pairs: Verify the requested currency pair is supported before displaying rates

Getting Help

  • 📧 Email: support@hifi.com
  • 💬 Slack: Message us in our shared Slack channel