# Automation: Ensure a function is called at regular intervals

## Overview

The CronJobTriggered source allows you to invoke any public function on any Ethereum Virtual Machine (EVM) blockchain network at a regular interval. &#x20;

## Setup

To create an Automation Midpoint, you need to know:

* the interval you need to make the calls
* the chain-id of the chain where the contract lives
* the address of the contract you want to call
* the signature of the function

#### Defining the interval

The CronJobTriggered source  is based on the Unix utility `cron`, which is used to schedule commands or scripts to run automatically at specified intervals.   It is controlled by a line of text, consisting of five fields, representing what minute, hour, day of the month, month, and day of the week the function should be called.  For example, to request that the function be called every hour on the hour, the line is `0 * * * *` .  If you wanted it called at two o’clock in the morning every Monday, use `0 2 * * 1`. To learn more about `cron` and cron-compatible strings, please refer to the [Wikipedia page for `cron`](https://en.wikipedia.org/wiki/Cron).

#### The chain-id

You can look up the chain-id for the chain you want to use here: [Chain IDs](/midpoint-documentation/more-reading/chain-ids.md)

#### The address of the contract

Remix or whatever tool you used to create the contract will give you the address.  It’s a 40-digit hex number, like this : `0xc1bebd66dfde46788c78f38b6f402d2ef17a9f9c`

#### The signature

The “signature” (nothing to do with a cryptographic signature) of a function consists of

* its name
* the number of arguments
* the type of each argument

You will also need to select value to give each argument.  The same value will be sent each time, unless you want to send the current time (called the “Timestamp”), since no new data is coming from the outside.

## Midpoint

#### **1 . Cron Job Triggered**

`$ 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": "* 12 * * *"
    "extracts": [
      {
        "name": "currentTime",
        "from": "{{Timestamp}}"
      }
    ]
  }
}
```

#### **2.  Transact To EVM Function**

`$ midpoint add-task transactToEvmFunctionTestnet post-time-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": "5",
    "contractAddress": "0x83986ff4fbcaa2acf6092930fcebbe25583be452",
    "functionName": "heartbeat",
    "arguments": [
      {
        "name": "time",
        "datatype": "uint256",
        "value": "{{currentTime}}"
      }
    ]
  }
}
```

#### **3.  Define Path**

We define our path file.&#x20;

```
cron-job-source => post-time-on-blockchain
```

#### **4.  Publish Midpoint**

`$ midpoint publish`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.midpointapi.com/midpoint-documentation/get-started/sample-midpoints/automation-ensure-a-function-is-called-at-regular-intervals.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
