Comment on page
Automation: Ensure a function is called at regular intervals
The CronJobTriggered source allows you to invoke any public function on any Ethereum Virtual Machine (EVM) blockchain network at a regular interval.
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
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
cronand cron-compatible strings, please refer to the Wikipedia page for
Remix or whatever tool you used to create the contract will give you the address. It’s a 40-digit hex number, like this :
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 add-source cronJobTriggeredSource cron-job-source
"crontab": "* 12 * * *"
$ midpoint add-task transactToEvmFunctionTestnet post-time-on-blockchain
We define our path file.
cron-job-source => post-time-on-blockchain
$ midpoint publish