Since 2009, we have been utilizing our extensive expertise in blockchain technologies to help businesses, both large and small, maximize their efficiency.
Explore More
With more than 400+ experts, Oodles comprises a fantastic resource of business knowledge that spans multiple industries. Whatever the circumstances, we keep to our obligations.
Explore More
At Oodles, we help our clients work with a human understanding but at superhuman speed something that others can't. They thus advance and maintain their lead
29th June 2023
8 min read
Senior Associate Consultant L1 - Development
Smart contract development plays a crucial role in oracle development and enables the seamless integration of real-world data into blockchain networks. With smart contracts, oracles can securely and autonomously retrieve and verify external data. Let's explore the process of developing an oracle using an Ethereum smart contract.
Oracles were created to enhance the possibilities of collaboration on blockchains. They establish connections between blockchains and external systems, enabling access to data from off-chain sources. Oracles act as a trusted source of information for the blockchain, providing secure gateways to off-chain systems. This allows smart contract applications to verify external events and trigger actions on external services.
Oracles essentially function as a link between two environments: the on-chain environment representing the blockchain network and the off-chain environment representing external systems in the real world.
Suggested Post | Blockchain Oracles | Making Smart Contracts Talk to the World
pragma solidity >=0.7.0 <0.9.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract EthPrice {
AggregatorV3Interface internal ethFeed;
bytes32 ethHash = keccak256(abi.encodePacked("ETH"));
constructor(_address) {
ethFeed = AggregatorV3Interface(_address);
}
function getEthPrice() public view returns (int) {(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = ethFeed.latestRoundData();
return price;
}
}
To get the address _address(Price feed contract address) of click here
Deploy the contract from the Deployment tab in Remix and run the function.
This code represents a Solidity smart contract called EthPrice that retrieves the latest price of Ethereum (ETH) using a Chainlink price feed.
Here's a breakdown of the code:
pragma statement defines the version range of Solidity that the contract is compatible with.import statement imports the AggregatorV3Interface from the Chainlink library. This interface provides functions to interact with Chainlink price feed contracts.EthPrice contract has an internal variable ethFeed of type AggregatorV3Interface. It will be used to interact with the Chainlink price feed.ethHash variable stores the keccak256 hash of the string "ETH". This can be used as an identifier or key for Ethereum.constructor function is used to initialize the contract. It takes an _address parameter representing the address of the Chainlink price feed contract. It assigns the provided address to ethFeed.getEthPrice function is a view function that retrieves the latest ETH price from the Chainlink price feed. It returns the price as an int.
latestRoundData function from the ethFeed contract.latestRoundData function fetches the latest round data from the Chainlink price feed.price value is extracted from the tuple and returned.
In summary, the EthPrice contract interacts with a Chainlink price feed to retrieve the latest price of Ethereum (ETH) and provides a function getEthPrice to access this price from other contracts or externally.
Interested in Oracle development using smart contracts? Connect with our smart contract developers to get started.
Yogesh Sahu
Yogesh is a highly experienced backend developer with a strong command over Node.js, MongoDB, Express, and Git/GitHub. He specializes in developing scalable and reliable web applications using JavaScript and Node.js. Additionally he has extensive knowledge of Ethereum, Solidity, and Smart Contracts, and he has worked on various blockchain projects, smart contracts, and implementing various blockchain protocols as well. With a background in backend development, he has built RESTful APIs, implemented authentication and authorization mechanisms, and developed expertise in blockchain technology.
Senior Associate Consultant L1 - Development
By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.
We would love to
hear from you!
Innovate with confidence!