> For the complete documentation index, see [llms.txt](https://docs.midpointapi.com/midpoint-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.midpointapi.com/midpoint-documentation/get-started/sample-midpoints/data-feed-stream-a-data-feed-on-chain-at-regular-intervals.md).

# 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:**&#x20;

1. Time-based job scheduler defined in the CronJobTriggered Source definition.

**MakeHttpRequest Task:**&#x20;

1. Makes an API request to the coinbase domain in a secure manner
2. Extracts the ethPrice from the API response
3. Sends the price to the Transact To EVM Function task

**TransactToEvmFunction task:**

1. 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**&#x20;

`$ midpoint add-source cronJobTriggeredSource cron-job-source`

We define the [Cron Job Triggered](/midpoint-documentation/sources/cron-job-triggered.md) source so that contract can make a midpoint request.&#x20;

```json
{
    "cronJobTriggeredSource": {
        "crontab": "* * * * *",
        "excludeLogs": [],
        "extracts": [
            {
                "name": "Midpoint_ID",
                "from": "Midpoint_ID"
            }
        ]
    }
}
```

**2.  Make Http Request**

`$ midpoint add-task makeHttpRequest get-eth-price`

We define the [Make HTTP Request](/midpoint-documentation/tasks/make-http-request.md) Task to get the ethPrice from the coinbase endpoint. &#x20;

```json
{
    "makeHttpRequest": {
        "urlRaw": "https://api.coinbase.com/v2/prices/ETH-USD/spot",
        "method": "GET",
        "urlType": "raw",
        "extracts": [
            {
                "name": "ethPrice",
                "from": "body.data.amount"
            }
        ]
    }
}
```

#### **3. Shift Decimal**

`$ midpoint add-task makeHttpRequest shift-eth-price`

We define the [Shift Decimal](/midpoint-documentation/tasks/shift-decimal.md) Task to return a usable price on-chain.&#x20;

```json
{
    "shiftDecimal": {
        "inputValue": "{{ethPrice}}",
        "decimalPlaces": "5",
        "outputName": "ethPriceScaled",
        "round": "false",
        "excludeLogs": []
    }
}
```

#### **4.  Transact To EVM Function**

`$ midpoint add-task transactToEvmFunctionTestnet post-eth-price-on-blockchain`

We define the [Transact to EVM Function](/midpoint-documentation/tasks/transact-to-evm-function.md) Task to send the summary back to the contract.&#x20;

```json
{
    "transactToEvmFunctionTestnet": {
        "chainId": "80001",
        "contractAddress": "0xC05f817a17bC0c505E48AC9CC52b5cb556F7B296",
        "arguments": [
            {
                "name": "Midpoint_ID",
                "datatype": "uint64",
                "value": "{{Midpoint_ID}}"
            },
            {
                "name": "EthPrice",
                "datatype": "uint64",
                "value": "{{ethPriceScaled}}"
            }
        ],
        "functionName": "latestEthPrice"
    }
}
```

#### **5.  Define Path**

We define our path file.&#x20;

```
cron-job-source => get-eth-price
get-eth-price => shift-eth-price
shift-eth-price => post-eth-price-to-blockchain
```

#### **6.  Publish Midpoint**

`$ midpoint publish`
