Overview
ThegetSolPrice() method fetches the current SOL/USD exchange rate from Pyth Network’s Hermes API. This is useful for displaying storage costs in fiat currency or showing wallet balances in USD.
Basic Usage
Return Value
The method returns aPromise<number> representing the current SOL price in USD.
Use Cases
Display Storage Costs in USD
Show users how much storage will cost in both SOL and USD:Display Wallet Balance in USD
Convert SOL balance to fiat currency:Check Affordability
Verify if a user has enough balance before uploading:Using with SWR (Recommended)
For automatic caching and revalidation in React, use SWR or a similar library like TanStack Query.Data Source
The price is fetched from Pyth Network’s Hermes API, which provides high-frequency, tamper-proof price feeds for cryptocurrencies.- Feed ID:
0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d - Update Frequency: Real-time (sub-second)
Related Methods
estimateStorageCost
Calculate storage costs in SOL
createDeposit
Upload files with SOL payment