Published in


Oracles and Smart Contracts

Integrating Chainlink Oracles With Smart Contracts On The Ethereum Blockchain

ETH/USD Price Feeds (Source Chainlink)

Connecting To Data

Get Latest Price Feed

//SPDX-License-Identifier: MITpragma solidity ^0.8.7;import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";contract GetPriceFeed {AggregatorV3Interface internal priceFeed;constructor() {
priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
function getPrice() public view returns (int) {
int price,

) = priceFeed.latestRoundData();
return price;
function latestRoundData() external view returns ( 
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound );

Deploying The Contract

The getPrice() function call returns our ETH price converted to USD (US Dollar)
web3.eth.getBalance("0x32aF98327E025547926AeD377e41C95169C6A6dd").then(function(result) { console.log(web3.utils.fromWei(result, "ether")) })




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Tabora

Editor HD-PRO, DevOps Trusterras (Cybersecurity, Blockchain, Software Development, Engineering, Photography, Technology)