Solidity theorytheory 0/50 · 0%
Integration · hard

37. Oracles and price feeds

Getting off-chain data safely.

Contracts cannot make HTTP calls, so oracles push data on chain. When reading a feed, check the answer is positive and the update is fresh; a stale price is how many protocols were drained.

(, int256 answer,, uint256 updatedAt,) = feed.latestRoundData();
require(answer > 0 && block.timestamp - updatedAt < 1 hours, "stale");

Never price an asset with a spot AMM reserve read — it can be manipulated within one flash-loaned transaction. Use a time-weighted average or an aggregated feed.

Check your understanding

  1. 1. What must you validate on a price feed?

  2. 2. Why is a spot AMM price unsafe?

  3. 3. Can a contract call an HTTPS API?