Pyth Network Integration (Oracles)
Pyth Network — Chainlink alternative with different model: first-party data sources. Prices supplied directly by financial institutions — Jane Street, Jump Trading, Cboe. Sub-second updates (400ms latency). Dominates Solana, actively growing in EVM ecosystem via cross-chain infrastructure.
Pull vs Push Oracle Model
Chainlink (Push): operators periodically update price on-chain. Price always available in smart contract. Updates happen per time or deviation-based triggers. Gas paid by Chainlink protocol.
Pyth (Pull): prices updated off-chain constantly. For on-chain use — user includes price update in transaction. User pays gas. Gives sub-second freshness without constant on-chain transactions.
EVM Integration
Setup
npm install @pythnetwork/pyth-sdk-solidity
npm install @pythnetwork/pyth-evm-js
Smart Contract
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
contract PythConsumer {
IPyth pyth;
bytes32 constant ETH_USD_PRICE_ID =
0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace;
constructor(address pythAddress) {
pyth = IPyth(pythAddress);
}
function doSomethingWithPrice(bytes[] calldata updateData) external payable {
// Update price (user pays fee)
uint fee = pyth.getUpdateFee(updateData);
pyth.updatePriceFeeds{value: fee}(updateData);
// Get updated price
PythStructs.Price memory price = pyth.getPriceNoOlderThan(
ETH_USD_PRICE_ID,
60 // max age in seconds
);
int256 ethPrice = price.price * int256(10 ** (18 + price.expo));
}
}
Frontend: Getting updateData
import { PriceServiceConnection } from "@pythnetwork/pyth-evm-js";
const connection = new PriceServiceConnection("https://hermes.pyth.network");
const priceUpdateData = await connection.getLatestVaas([ETH_USD_PRICE_ID]);
// Pass in transaction
await contract.doSomethingWithPrice(priceUpdateData, { value: updateFee });
Confidence Interval
Unique to Pyth — each price includes confidence interval (conf). Standard deviation across sources.
Allows protocol to protect itself from unreliable prices.
Pyth excellent for protocols requiring high-frequency price updates (perp DEX, lending with liquidations in volatile conditions).







