Oracle

DeFi

Définition

Service permettant aux smart contracts d'accéder à des données externes (prix des actifs, résultats sportifs, météo, etc.). La blockchain ne peut pas accéder au monde réel par elle-même, les oracles comblent ce fossé. Chainlink est le leader du marché. Risques : centralisation, manipulation, latence.

Version anglaise

Service allowing smart contracts to access external data (asset prices, sports results, weather, etc.). Blockchain cannot access real world by itself, oracles bridge this gap. Chainlink is market leader. Risks: centralization, manipulation, latency.

Exemple de Code

// Interface Chainlink Price Feed
interface AggregatorV3Interface {
  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

contract PriceConsumer {
  AggregatorV3Interface internal priceFeed;

  constructor() {
    priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); // ETH/USD Mainnet
  }

  function getLatestPrice() public view returns (int) {
    (,int price,,,) = priceFeed.latestRoundData();
    return price; // Prix en 8 décimales
  }
}

Pratique ce concept sur Solingo

Maîtrise Oracle avec des exercices interactifs et un IDE intégré.

Commencer gratuitement