Book a free call

Blockchain Oracle Best Practices for Teams That Rely on Feeds

A blockchain oracle feeds off-chain prices into your contracts, so a bad feed can drain a protocol. These practices keep feeds honest, fresh and hard to break.

Hertiv engineering teamReviewed by a senior engineer
8 min read
Blockchain Oracle Best Practices for Teams That Rely on Feeds
On this page

Short answer

Blockchain oracle best practices are: use several independent data sources, aggregate with a median rather than a single price, check that the feed is fresh before you act on it, set deviation thresholds and circuit breakers, and keep a fallback feed ready. Most oracle failures come from stale data or a single source, not from the contract code.

What are blockchain oracle best practices?

Blockchain oracle best practices are the habits that keep the data flowing into a smart contract honest, fresh and hard to break. A blockchain oracle is a service that brings off-chain information, usually a price, onto a chain so a contract can use it. Contracts cannot fetch that data themselves, so they depend on the oracle completely.

That dependence is the risk. If the price feed is wrong, stale or manipulated, the contract will still act on it, because the contract has no way to know the data is bad. Lending, derivatives, stablecoins and insurance products all depend on oracle prices, so a bad feed can liquidate healthy positions or let an attacker borrow against an inflated price.

The practices in this article cover five areas: choosing the design, keeping feeds trustworthy, handling downtime and bad data, managing keys and upgrades, and testing before launch. They apply whether you use a third-party oracle network or run your own feed, and they are the operational side of the implementation steps in how to implement a blockchain oracle.

The short version is simple. Never trust one source, never trust an old price, and never let a bad feed run without a brake. The sections below turn that into checks you can build.

Which oracle design fits your use case?

The right oracle design depends on what the data is used for and how much a wrong answer would cost. A price feed for a lending market needs more protection than a feed that shows a price on a dashboard, because the lending feed moves money.

Design How it works Best for
Decentralised network Many nodes report, answers are aggregated Price feeds for lending and derivatives
Single trusted feed One provider signs the data Low-value displays and tests
Push feed Updates arrive on a schedule or on change Assets that move often
Pull feed Contract requests data when needed Occasional checks and settlements
Cross-check Two feeds compared before use High-value actions such as liquidation

For most production use, a decentralised network with aggregation is the default. A single source is acceptable only where a wrong answer costs little, such as a display. If you are choosing between providers, the shortlist in best blockchain oracles for startups covers the networks teams compare most often.

How do you keep price feeds trustworthy?

A trustworthy price feed starts with several independent sources. A single exchange price can be moved by a large trade or an outage, so the oracle should draw from several exchanges and market makers, and combine the answers with a median rather than an average. A median ignores the highest and lowest reports, which limits what one bad source can do.

Deviation thresholds are the second control. If a new price moves more than a set amount from the last accepted price, the update should be held for review or rejected. The threshold depends on the asset: a stablecoin feed needs a tight threshold, while a volatile token needs a wider one, or normal market moves will trip the control constantly.

Source quality matters as much as source count. A feed that draws from three exchanges owned by the same company is not three independent sources. Ask the provider where its data comes from, how it handles an exchange outage, and what happens when a source stops reporting. The answers to those questions tell you more about reliability than any marketing claim.

Finally, keep the feed's history. Store each accepted price with its time and sources, so an incident can be reconstructed later. Without that record, a dispute about a liquidation or a settlement is very hard to resolve. What is a blockchain oracle explains the basic model these controls sit on.

How do you handle downtime and bad data?

Feeds go stale, and the contract must notice. Every price the contract uses should carry a timestamp, and the contract should refuse to act if the timestamp is older than a limit you set. That limit, often called the staleness check, is one of the most important lines in an oracle integration, and it is also one of the most often skipped.

Circuit breakers are the second defence. If the price moves too far, if the feed stops updating, or if two feeds disagree by more than a set amount, the contract should pause the affected action rather than continue on bad data. Pausing a lending market for an hour is far cheaper than liquidating users on a wrong price. The pause must be reversible, and someone must be on call to lift it.

A fallback feed is the third defence. If the primary feed fails, the contract should switch to a second feed or a second provider, or stop accepting new positions until the primary feed returns. The fallback needs its own staleness check, because a fallback that is also stale helps no one. Test the switch regularly, not only when the primary feed fails.

Monitor the feed like a production service, not like a library. Alert on missed updates, on deviation threshold hits, on source dropouts and on any pause. An alert that nobody reads is the same as no alert, so name the person who responds and the runbook they follow.

How do you manage keys, upgrades and access?

Oracle feeds are updated by someone, and that someone's keys are a target. Feed updates should be signed by several keys held by different people, not by one key on one laptop. A single compromised key should not be able to push a false price, and a single lost key should not be able to stop updates.

Upgrades need the same care. If the oracle contract can be upgraded, the upgrade should pass through a timelock, so users can see the change coming and exit if they disagree. An upgrade that takes effect instantly gives users no chance to react, and it gives an attacker who gains control no delay either.

Access control should follow the same rule as the rest of the system: the smallest permission that fits the job, for the shortest time. The key that pushes prices should not also be able to pause the whole protocol, and the key that pauses should not be able to move funds. Separate the roles, and review who holds each one at least quarterly.

Finally, test the oracle the way you test the contract. Run the feed against a testnet with real market conditions, simulate a stale feed, simulate a source dropping out, and simulate a price spike. The audit of the oracle integration should cover the feed logic, the staleness checks and the pause paths, not just the contract code. A smart contract audit that skips the oracle leaves the largest risk untested.

Example (hypothetical): a lending app checks a stale feed

Example (hypothetical): a lending app accepts a token as collateral. A user deposits collateral worth $20,000 and borrows $12,000, so the loan is 60% of the collateral value. The app liquidates a position when the loan reaches 85% of the collateral value.

The price feed updates every 5 minutes. One afternoon the feed goes silent for 40 minutes, which is 8 missed updates. The app's staleness check is set to 15 minutes, so after 15 minutes the contract stops accepting new loans and stops liquidating positions. Users see a warning that prices are stale.

When the feed returns, the token price has fallen 25%. The collateral is now worth $15,000, and the loan of $12,000 is 80% of that value, which is below the 85% liquidation threshold, so the position is not liquidated. The user has time to add collateral or repay part of the loan.

Without the staleness check, the app would have kept liquidating on the old price, or kept lending against collateral that was worth less than the app believed. The check cost one line of code and one afternoon of testing, and it prevented a loss that would have taken weeks to explain to users.

What are the common mistakes?

The most common oracle mistakes are trusting one source, skipping the staleness check, and never testing the failure paths.

  • One source. A single exchange price can be moved by a large trade or an outage. Use several independent sources and aggregate with a median.
  • No staleness check. A price from an hour ago is not a price. Refuse to act on data older than your limit.
  • No circuit breaker. Without a pause, a bad feed keeps running until someone notices. Pause on large moves, stale data and feed disagreement.
  • No fallback. If the primary feed fails and there is no second feed, the protocol stops or, worse, keeps going on old data.
  • One key for everything. A single key that can push prices and pause the protocol is a single point of failure. Split the roles.
  • Instant upgrades. An upgrade with no timelock gives users no chance to react. Use a timelock and announce the change.
  • Untested failure paths. Simulate a stale feed, a dropped source and a price spike on testnet before launch, and repeat the test after every change.

If you are building a protocol that depends on price feeds, a blockchain development review of the oracle integration is worth doing before launch.

Key takeaways

  • Never trust one source: use several independent sources and aggregate with a median
  • Refuse to act on stale data: every price needs a timestamp and a staleness limit
  • Add circuit breakers that pause the affected action on large moves or feed disagreement
  • Keep a fallback feed ready, and test the switch before you need it
  • Split oracle keys by role, and put upgrades behind a timelock
  • Test stale feeds, dropped sources and price spikes on testnet before launch

Frequently asked questions

What is a blockchain oracle?

A blockchain oracle is a service that brings off-chain information, usually a price, onto a blockchain so a smart contract can use it. Contracts cannot fetch external data themselves, so they depend on the oracle for any fact about the outside world.

Why do oracles need several data sources?

A single source can be wrong, manipulated or offline. Several independent sources combined with a median limit what one bad source can do, because the highest and lowest reports are ignored when the median is taken.

What is a staleness check?

A staleness check is a rule that refuses to use a price older than a set limit. If the feed stops updating, the contract stops acting on old data instead of lending or liquidating against a price that no longer reflects the market.

What is an oracle circuit breaker?

A circuit breaker pauses an action when something looks wrong, such as a price moving too far, a feed going stale, or two feeds disagreeing. Pausing for an hour is far cheaper than liquidating users on a wrong price.

Should I run my own oracle or use a network?

Most teams use a decentralised oracle network, because running a reliable feed is a full-time job. A custom feed makes sense only when the data is unusual and no network covers it, and it needs the same controls: several sources, staleness checks and a fallback.

How do I test an oracle integration?

Simulate the failures on a testnet: stop the feed, drop a source, push a price spike, and check that the staleness check, the circuit breaker and the fallback all behave as designed. Repeat the test after every change to the integration.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a protocol that depends on price feeds? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Smart Contract Audit service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call