📌Crypto Price Feed Contract
Introduction
The Crypto Price Feed Oracle is a decentralized smart contract designed to fetch real-time cryptocurrency price data and provide it to other smart contracts. Acting as a bridge between blockchain applications and external data sources, this oracle enables smart contracts to securely and transparently access real-world cryptocurrency price information.
Technical Description
The Crypto Price Feed Oracle is implemented as a smart contract on a blockchain platform such as Ethereum. It listens for cryptocurrency price data requests, fetches real-time price information from an external API, and stores the data in a decentralized manner. This ensures accessibility, security, and immutability.
Workflow
A user invokes the contract by providing a
_symbol_crypto
(e.g., "ETH").The contract makes an external API request to fetch the latest price of the specified cryptocurrency.
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 cryptocurrency price data.
Key Features
Secure and tamper-proof storage of cryptocurrency price data.
Transparent and publicly accessible data.
Pay-per-use model for requesting cryptocurrency price information.
Event-driven updates that notify subscribers when new data is available.
Usage
To interact with the Crypto Price Feed Oracle, follow these steps:
1. Deploy the Contract
Deploy the contract to the blockchain using the following Oracle Contract address:
2. Request Cryptocurrency Price Data
Call the function:
_symbol_crypto
: The ticker symbol of the cryptocurrency (e.g., "ETH", "BTC")._sender_address
: The address of the user making the request.This is a payable function, meaning the user must pay a certain amount of Ether to access the price data.
On successful execution, the function returns a unique request ID.
3. Retrieve Cryptocurrency Price Data
Once the data is available, call:
id
: The request ID received from the previous function.This function retrieves the latest cryptocurrency price data.
Smart Contract Implementation
Contract Functions
1. Constructor
Initializes the contract with the address of the CryptoPriceFeedOracle smart contract.
2. Request Cryptocurrency Price Data
Allows users to request price data for a specific cryptocurrency.
Requires a payable transaction where users must send Ether to access the data.
Takes in
_symbol_crypto
(cryptocurrency ticker symbol) and_sender_address
(user's address).Calls the
add
function on the Oracle contract to store the requested data and generate an ID.Returns:
symbol_crypto
: The requested cryptocurrency symbol.sender
: Address of the requester.id
: Unique request ID.
3. Retrieve Cryptocurrency Price Data
Fetches stored cryptocurrency price data for a given request ID.
Calls
getCryptoData
function on the Oracle contract.Returns:
price
: The latest price of the requested cryptocurrency.
Last updated