📌Weather Feed Contract
Introduction
The Weather Feed Oracle is a decentralized smart contract designed to fetch real-time weather data and provide it to other smart contracts. Acting as a bridge between blockchain applications and external weather data sources, this oracle enables smart contracts to access and utilize real-world weather information securely and transparently.
Technical Description
The Weather Feed Oracle is implemented as a smart contract on a blockchain platform such as Ethereum. It listens for weather data requests, fetches real-time weather information from an external weather API, and stores the data in a decentralized manner. This ensures accessibility, security, and immutability.
Workflow
A user invokes the contract by providing a
_location
(city name).The contract makes an external API request to fetch weather data for the specified location.
The retrieved data is stored in the contract’s storage and an event is triggered.
Other smart contracts or users can monitor this event and retrieve the stored weather data.
Key Features
Secure and tamper-proof storage of weather data.
Transparent and publicly accessible data.
Pay-per-use model for requesting weather information.
Event-driven updates that notify subscribers when new data is available.
Usage
To interact with the Weather Feed Oracle, follow these steps:
1. Deploy the Contract
Deploy the contract to the blockchain using the following Oracle Contract address:
2. Request Weather Data
Call the function:
_location
: The city name for which weather data is requested.This is a payable function, meaning the user must pay a certain amount of Ether to access the data.
On successful execution, the function returns a success message.
3. Retrieve Weather Data
Once the data is available, call:
_location
: The city name for which data was previously requested.This function retrieves the latest weather data, including temperature and weather description.
Smart Contract Implementation
Contract Functions
1. Constructor
Initializes the contract with the address of the Oracle smart contract.
2. Request Weather Data
Allows users to request weather data for a specific location.
Requires a payable transaction where users must send Ether to access the data.
Takes in
_location
(city name) as a parameter.Calls the
requestWeather
function on the Oracle contract to fetch the data.Returns a success message if the request is processed correctly.
3. Retrieve Weather Data
Fetches stored weather data for a given location.
Calls
getWeather
function on the Oracle contract.Returns:
temperature
: The current temperature.weather_description
: The weather condition (e.g., sunny, rainy, cloudy).
Last updated