Fetch live stablecoin prices from the IFÁ Labs oracle in your Solidity smart contracts: single-asset reads, batch reads, and derived currency pairs.
With your contract configured and the interface installed, reading a price is a single view call. This page covers three reading patterns: single asset, batch, and derived pairs. Use whichever fits your protocol’s needs — or combine them.
If your protocol needs multiple prices in the same transaction — for example, valuing a multi-asset collateral basket — use getAssetsInfo. One external call is always cheaper than multiple individual calls.
bytes32[] memory assetIds = new bytes32[](3);assetIds[0] = USDT_ASSET_ID;assetIds[1] = USDC_ASSET_ID;assetIds[2] = CNGN_ASSET_ID;(IIfaPriceFeed.PriceFeed[] memory infos, bool[] memory exists) = ORACLE.getAssetsInfo(assetIds);for (uint256 i = 0; i < assetIds.length; i++) { require(exists[i], "IFA: unsupported asset in batch"); // Process infos[i].price, infos[i].decimal, infos[i].lastUpdateTime}
The exists array is returned in the same order as the input assetIds array. Always check exists[i] before using infos[i] — a false value means that asset has no data and the corresponding PriceFeed fields will be zero.
Derived pairs let you price one supported asset directly against another — for example, CNGN priced in USDT terms, or BRZ priced in USDC terms — without requiring a dedicated feed for every possible combination.IFÁ Labs computes derived prices on-chain using the two underlying USD feeds as intermediates.
// Price CNGN in terms of USDT (how much USDT is one CNGN worth?)IIfaPriceFeed.DerivedPair memory pair = ORACLE.getPairbyId( CNGN_ASSET_ID, // asset0 — the asset being priced USDT_ASSET_ID, // asset1 — the denominator IIfaPriceFeed.PairDirection.Forward);
Derived pairs require both assets to have active, non-stale USD feeds. If either underlying feed is stale or missing, the derived pair calculation will revert. Always ensure both feeds are healthy before calling derived pair functions in critical paths.
These are the mistakes developers make most often when first reading from the oracle. All of them are avoidable.Not checking exists before using the price. If exists is false, info.price is 0. Using that value without checking will silently execute your logic against a zero price.Forgetting to apply the decimal scaling.info.price is not a dollar amount — it’s a scaled integer. 1000000000000000000 is $1.00, not one quintillion dollars. Always divide by 10^(-decimal) before using the value in human-facing output or fixed-point math.Casting int256 to uint256 without checking sign. Current stablecoin feeds always return positive prices, but the type is int256. Cast safely: only cast after confirming info.price > 0, or use uint256(info.price) with the understanding that negative values would underflow.Using the price without a staleness check. A returned price with exists = true is not automatically fresh. Always pair your read with a lastUpdateTime check before using the value in any logic with financial consequences. See Verify Price Integrity.