This guide covers oracle solutions for bringing off-chain data to Stellar/Soroban smart contracts.
Oracles provide external data (prices, events, etc.) to smart contracts. On Stellar, the primary oracle solution is Reflector Network, with additional options like DIA.
Smart contracts can't access external data directly. Oracles bridge this gap for:
- Price feeds - Token prices for DeFi protocols
- Random numbers - Gaming and lottery applications
- External events - Real-world data triggers
- Cross-chain data - Information from other blockchains
The primary community-powered price oracle for Stellar, implementing SEP-40.
| Feature | Details |
|---|---|
| Website | reflector.network |
| Docs | Stellar Oracle Providers |
| Standard | SEP-40 compatible |
Features:
- On-chain and off-chain price data
- Webhook notifications
- Community-operated nodes
- Multiple asset support
Integrations:
- Blend Protocol
- Orbit CDP
- DeFindex
- Laina
- EquitX
- Slender
Cross-chain oracle with extensive asset coverage.
| Feature | Details |
|---|---|
| Website | diadata.org |
| Blog | DIA on Soroban |
| Assets | 20,000+ supported |
Features:
- VWAPIR pricing methodology
- Custom feed configuration
- Cross-chain compatibility
- Enterprise support
use soroban_sdk::{contract, contractimpl, Address, Env};
#[contract]
pub struct MyContract;
#[contractimpl]
impl MyContract {
pub fn get_price(e: &Env, oracle: Address, asset: Address) -> i128 {
// Call oracle contract to get price
let price: i128 = e.invoke_contract(
&oracle,
&Symbol::new(e, "lastprice"),
vec![&e, asset.into_val(e)],
);
price
}
}SEP-40 oracles typically return:
pub struct PriceData {
pub price: i128, // Price in base units
pub timestamp: u64, // Unix timestamp
}- Use multiple sources - Cross-reference prices when possible
- Check staleness - Verify timestamp is recent
- Handle failures - Gracefully handle oracle unavailability
- Set boundaries - Reject prices outside reasonable ranges
- Consider latency - Account for block time in time-sensitive operations
- Oracle manipulation - Be aware of flash loan attacks
- Stale data - Always check price freshness
- Single point of failure - Consider decentralized oracles
- Price deviation - Implement circuit breakers for large swings