๐Ÿ“šIntegration Guide

We implemented smart contract interfaces to connect your infrastructure with real-world data using eOracle.

Price feeds are a crucial component in the decentralized finance (DeFi) ecosystem, allowing for a wide range of financial activities such as lending, borrowing, trading, and derivatives. Price feeds enable dapps to access accurate and updated pricing data in a secure and trustless manner.

eOracle price feeds aggregate information from many different data source and are published on-chain for easy consumption by dApps. This guide shows you how to read and use eOracle price feeds using Solidity.

Reading eOracle price feeds on EVM-compatible blockchains follows a consistent format for both queries and responses across different chains.

If you are currently using a different Oracle solution and wish to transition, consider eOracle Adapter.

Prerequisites

The guide assumes you have a basic understanding of smart contract development.

This example contract obtains the latest BTC:USD price feed answer from the Holesky testnet.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IEOFeedManager {
    struct PriceFeed {
        uint256 value;
        uint256 timestamp;
    }

    function getLatestPriceFeed(uint16 symbol) external view returns (PriceFeed memory);
    function getLatestPriceFeeds(uint16[] calldata symbols) external view returns (PriceFeed[] memory);
}

contract EOConsumerExample {
    IEOFeedManager public _feedManager;

    /**
     * Network: Holesky
     * FeedManager: 0x723BD409703EF60d6fB9F8d986eb90099A170fd0
     */
    constructor() {
        _feedManager = IEOFeedManager(0x723BD409703EF60d6fB9F8d986eb90099A170fd0);
    }

    // Example for using IEOFeedManager.getLatestPriceFeed with a single feed.
    function getPrice() external view returns (IEOFeedManager.PriceFeed memory) {
        return _feedManager.getLatestPriceFeed(1); // 1 is the id for BTC:USD
    }

    function usePrice() external {
        IEOFeedManager.PriceFeed memory data = this.getPrice();
        uint256 value = data.value;
        uint256 timestamp = data.timestamp;
        // Do something
        // .............
    }
}

Edit/Deploy using Remix by clicking here

The code has the following elements:

  • An interface for an external feed manager, IEOFeedManager, to retrieve price feeds.

  • The IEOFeedManager interface defines two functions: getLatestPriceFeed to fetch the latest price feed for a single symbol, and getLatestPriceFeeds to retrieve price feeds for multiple symbols at once.

  • In the constructor, the contract initializes the feed manager, connecting specifically to a feed manager contract deployed on the Holesky network at address 0x723BD409703EF60d6fB9F8d986eb90099A170fd0.

  • The getPrice() function demonstrates fetching the latest price feed for a single symbol, in this case, the price of BTC to USD.

  • The usePrice() function exemplifies how to use the retrieved price feed data. It calls getPrice() internally, extracts the price value and timestamp from the returned PriceFeed struct, and performs further operations based on the fetched data.

Contact support@eoracle.io for more details on deployments and usage.

Last updated