What is a blockchain oracle and how do you use price data safely?
What the interviewer wants to hear
- Contracts cannot fetch off-chain data themselves
- Oracles bring data such as prices on chain
- Decentralised oracle networks like Chainlink
- Check staleness, decimals and sequencer uptime on L2
- Avoid spot prices from a single pool; use TWAP or multiple sources
- Circuit breakers for extreme values
Model answer
Smart contracts cannot call external APIs, so anything from the outside world, like the ETH/USD price, must be pushed on chain by an oracle. Decentralised oracle networks such as Chainlink, or pull-based ones like Pyth, aggregate data from many sources and node operators. When I use a price feed, I check that the answer is positive, that updatedAt is recent compared with the feed's heartbeat so I am not using stale data, and I handle decimals correctly since feeds and tokens use different decimals. On Layer 2 networks I also check the sequencer uptime feed, because prices can be stale after an outage. I never use the spot price from a single DEX pool, because flash loans can move it in one transaction; if I need an on-chain price, I use a time-weighted average over enough time. For critical protocols I add sanity bounds and a fallback or pause when prices move unrealistically.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Blockchain Developer questions
- What is a reentrancy attack and how do you prevent it?
- What techniques do you use to reduce gas costs in Solidity contracts?
- How do you test a smart contract before deploying it to mainnet?
- How do upgradeable smart contracts work, and what are the trade-offs?
- How do signature-based approvals like ERC-2612 permit and Permit2 work, and what are their risks?
- How do you build a reliable dApp frontend that reads and writes contracts with viem and wagmi?
- How do chain reorganizations affect a dApp or backend service, and how do you handle them?
- How do you design admin control for a protocol so it can be maintained without making users trust a single person?
- Walk me through how you deploy a set of contracts to mainnet safely.