Quick Start

Here is a quick Start guide for using the DATUM Oracles

Good to know: A quick start guide can be good to help folks get up and running with your contracts in a few steps. Some people prefer diving in with the basics rather than meticulously reading every page of documentation!

Install the Contract library

The best way to interact with oracles is to use one of our official libraries:

# Install via NPM
npm i datum-contracts

Make your first request

To make your first request, import the Oracles interface you want to try out

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.14;

import "datum-contracts/interfaces/PriceOracleInterface.sol";

Good to know: There are various type of Oracles under DATUM choose one that suites you the best and try it out.

Here is an full example the contract for testing Price Oracles :

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.14;

// *************************************
// *   Minimum Viable Price Oracle  *
// *************************************

// This contract shows how to get up and running as quickly as posible with Chainlink's Price Feeds
// We make a simple price request to the Oracle and getLatestPrice

import "datum-contracts/interfaces/PriceOracleInterface.sol";

contract PriceOracleTest {
    PriceOracleV1 _priceOracle =
        PriceOracleV1(0x9eDf5612D5108dD5BcCb2da086a2C52ef58b03a0);

    // Submit a data request to the oracle
    /**
    Price Feedsfor goerli Address
    Pair: BTC/ETH
    PairAddress: 0x779877A7B0D9E8603169DdbD7836e478b4624789
     */
    function requestPrice() public {
        _priceOracle.requestPairPrice(
            0x779877A7B0D9E8603169DdbD7836e478b4624789
        );
    }

    // Fetch the resolved price from the Optimistic Oracle that was settled.
    function getPrice() public view returns (uint) {
        return
            _priceOracle.getLatestPrice(
                0x779877A7B0D9E8603169DdbD7836e478b4624789
            );
    }
}
  • Go to Remix and Compile the Contract after heading over to the tab

  • Later connect with Injected Web3 Provider with Metmask , deploy the contract From Deploy tab on Sepolia for testing

  • Then you can call getPrice() to get the latest price from the Oracle.

Last updated