Data Feed: Stream a data feed on-chain at regular intervals
Overview
A Data Feed utilizes a cron job, which is a time-based job scheduler in Unix-like operating systems, to automatically trigger the submission of transactions to a smart contract on a blockchain. This means that the program will execute the transaction submission at regular intervals without requiring any manual intervention.
CronJobTriggered Source:
Time-based job scheduler defined in the CronJobTriggered Source definition.
MakeHttpRequest Task:
Makes an API request to the coinbase domain in a secure manner
Extracts the ethPrice from the API response
Sends the price to the Transact To EVM Function task
TransactToEvmFunction task:
Sends back the ethPrice to the contract via function defined by the user in the next block
Midpoint
$ npm install -g midpoint-cli
$ midpoint init blank my-data-feed
1 . Cron Job Triggered
$ midpoint add-source cronJobTriggeredSource cron-job-source
We define the Cron Job Triggered source so that contract can make a midpoint request.
2. Make Http Request
$ midpoint add-task makeHttpRequest get-eth-price
We define the Make HTTP Request Task to get the ethPrice from the coinbase endpoint.
3. Shift Decimal
$ midpoint add-task makeHttpRequest shift-eth-price
We define the Shift Decimal Task to return a usable price on-chain.
4. Transact To EVM Function
$ midpoint add-task transactToEvmFunctionTestnet post-eth-price-on-blockchain
We define the Transact to EVM Function Task to send the summary back to the contract.
5. Define Path
We define our path file.
6. Publish Midpoint
$ midpoint publish
Last updated