How Hedera calculates the HBAR / USD exchange rate for SDKs and applications

How Hedera calculates the HBAR / USD exchange rate for SDKs and applications

Background

By: Devin Saxon, Atul Mahamuni & Keith Kowal

Most blockchains peg their transaction fees to the value of a token. When the value of that token fluctuates it therefore also causes the cost of transactions on that network to also fluctuate. In contrast Hedera pegs transaction fees to a static value in USD, but with the actual fees paid in HBAR. To achieve this Hedera has developed tooling to provide regular recalibration of exchange rates. By offering consistent and transparent costs, Hedera's approach aligns with the expectations of businesses and enterprises that rely on stable operational expenses for scalability, and budget planning.

As such having up-to-date and accurate USD to HBAR conversion values is an important network component across various applications and services including:

1. Network Nodes: The exchange rate of HBAR is used to determine the cost of API calls (hbar prices for API calls on Hedera are calculated using the exchange rate so that the dollar equivalent of the price will change more slowly).

2. Hedera Fee Calculator: An interactive calculator on Hedera.com to estimate your costs and a table which lists the most common API calls, with pricing converted from USD to HBAR based on current rates.

3. Public APIs: Hedera offers a RestAPI to publicize the current USD-HBAR exchange rate used by the network to calculate fees.

Hedera Exchange Rate Tool

To calculate the exchange rate between USD and HBAR Hedera supports an open source Exchange Rate Tool (ERT) which can be found here. The design of ERT takes into account two primary operational considerations:

  1. If ERT were to rely on a single exchange rate data point that might be abused to sway the conversion rate. Therefore ERT must support multiple inputs on the current USD-HBAR exchange rate.

  2. Cryptocurrency values can be highly volatile so the ERT applies smoothing and clipping functions to make the rates smoother that better allows users to anticipate and support their HBAR expenditures.

Pulling the latest pricing from key exchanges

There are many exchanges that publish exchange rates between USD & HBAR. In order to reduce threats of centralization, ERT uses rates from the following exchanges:

Every hour ERT fetches the HBAR-USD exchange rate from the above exchanges. From these exchange rates, ERT calculates a volume-weighted median using the exchange rates and trading volumes on each of the exchanges. This approach ensures that exchanges with higher trading volumes have a greater influence on the final median rate.

Smoothing & Clipping

ERT compares the median exchange rate value to the value used from the previous midnight. If the newly calculated median changes the rate from last night by more than a threshold (currently 25% at the time of writing this document), then we clip the change in this rate to that threshold. This prevents wild swings in the exchange rates used by the Hedera networks while allowing it to catch up with the market rate eventually.

Further - because the prices of HBAR can be volatile - ERT implements clipping with a configurable floor currently set at $0.04 per HBAR.

Publishing ERT Exchange Rate

Once calculated, the validated and adjusted rate is packaged into an ExchangeRate file, which includes the Current Rate that is in effect, the Next Rate that should take effect, and the Expiration Time when the switchover should occur from the Current Rate to the Next Rate.

The Exchange Rate Tool then uploads this file to the consensus nodes, and the consensus nodes calculate the appropriate fees in HBAR accordingly. Currently, Hedera runs three ERT instances publishing to the mainnet, testnet, and previewnet networks.

The Hedera Fee calculator uses this same exchange rate value to ensure that the fees it projects accurately track the actual fees being charged on the network.

In addition the ERT exchange rates are published with a REST API here. A sample request and response is shown below.

Sample API Request: https://mainnet.mirrornode.hedera.com/api/v1/network/exchangerate

Sample API Response:
{

"current_rate": {

"cent_equivalent": 405644,

"expiration_time": 1732654800,

"hbar_equivalent": 30000

},

"next_rate": {

"cent_equivalent": 409246,

"expiration_time": 1732658400,

"hbar_equivalent": 30000

},

"timestamp": "1732651259.496599000"

}

Conclusion

The Hedera Exchange Rate tool is a key component that enables the Hedera network to offer stable transaction pricing. This in turn enables Hedera's transaction costs to remain predictable in terms of US Dollars and reduces the impact of market volatility strengthening the network's appeal to a wide range of stakeholders.