Price Data Feeds
Get price info on chain with Chainlink Price Feeds for multiple coin pairs
Data Feeds are the quickest way to connect your smart contracts to the real-world data such as asset prices, reserve balances, NFT floor prices, and L2 sequencer health.
Types of data feeds
Data feeds provide many different types of data for your applications.
Using Data Feeds
Start by importing the datum-contracts interface
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;
import "datum-contracts/interfaces/PriceOracleInterface.sol";
Now create an instance of the oracle-interface , and the Oracle Address should be the Price Oracle address for the chain , you are trying out
// For Sepolia
oracleAddress = 0x9eDf5612D5108dD5BcCb2da086a2C52ef58b03a0
PriceOracleV1 _priceOracle =
PriceOracleV1(oracleAddress);
You can call
requestPairPrice
to an updated price for the pair
_priceOracle.requestPairPrice(
pairAddress
);
Call
getLatestPrice
to get the price for the Pair directly
price = _priceOracle.getLatestPrice(
pairAddress
);
Full Example Contract Code
// 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
);
}
}
In there simple steps , you can get Price Feeds , ProofOfReserve feeds and NFTFloorPrices from the Chainlink Oracle to your chain with DATUM
Last updated