API ReferencePricing and oraclesFunction
getPrice()
function getPrice(ctx, params): Promise<Price>;Returns the current Pyth exchange rate from inputToken to outputToken as a
Price in smallest units of output per smallest unit of input, computed
with the same integer math as the on-chain PythPriceOracle. Both tokens need a Pyth feed (resolved
via getPriceFeedId). If Hermes is unavailable, the action returns the oracle’s
current on-chain pair price only after proving it fresh against the chain clock; otherwise it
preserves the typed price-server error.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | SDKContext | The SDK context. |
params | GetPriceParams | The parameters indicating which token is being priced in terms of the other token. |
Returns
Promise<Price>
The price object indicating the output-per-unit-input price between the tokens.
Example
const { price, exponent } = await sdk.pricing.getPrice({ inputToken: WETH, outputToken: USDC,});// price * 10**exponent = USDC smallest units per 1 wei; both tokens'// decimals are already folded in, so on-chain math uses it as-is. Rescale// by (18 - 6) only to show USDC per whole WETH.const usdcPerWholeWeth = Number(price) * 10 ** (Number(exponent) + 18 - 6);Throws
StalePythPriceError If Hermes returns a price outside
oracleConfig.maxPriceAgeSeconds. This unsafe-data failure does not use the on-chain fallback
reserved for PriceServerError.