Problem Faced:
Smart contracts cannot directly fetch real-world (off-chain) data, such as asset prices, weather conditions, or sports scores.
Solution:
Use oracles like Chainlink to bring external data onto the blockchain.
- Smart contracts request data from an oracle.
- The oracle fetches data from trusted APIs and pushes it back on-chain.
Using Chainlink Price Feed:
solididty
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumer {
AggregatorV3Interface internal priceFeed;
constructor() {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331); // ETH/USD on Rinkeby
}
function getLatestPrice() public view returns (int) {
(,int price,,,) = priceFeed.latestRoundData();
return price;
}
}
Build secure, scalable, and customized blockchain solutions tailored to your business needs. From smart contract development to decentralized applications, get end-to-end services for your blockchain projects. Our blockchain development ensures seamless integration, high security, and innovative solutions for Web3, DeFi, and enterprise blockchain applications. Let’s shape the future of decentralized technology together!
Top comments (0)