LogoLogo
MidpointContact UsThe Docs are Wrong!
  • What is Midpoint
  • What actually is a midpoint?
  • Midpoint FAQs
  • Get Started
    • Sample Midpoints
      • Filecoin Filrep Oracle: Obtain miner reputations on-chain
      • Oracle: Call any API from a smart contract
      • Listener: Subscribe an internal service to any event
      • Data Feed: Stream a data feed on-chain at regular intervals
      • Data Bridge: Pass arbitrary messages between chains
      • Automation: Ensure a function is called at regular intervals
    • Videos
  • Using Midpoint
    • API Key
    • Midpoint CLI
    • GraphQL API
    • Dashboard
  • Core Concepts
    • Midpoints
      • Midpoint ID
      • Sources
      • Tasks
      • Source and Task Definitions
        • Secrets
        • Variables
        • Exclude Logs
        • Extracts
    • Requests
      • Request ID
      • Events
    • Credits and Payment
  • Sources
    • Startpoint Called
    • EVM Event Emitted
    • Cron Job Triggered
  • Tasks
    • Make HTTP Request
      • OAuth and Multi-Step Authentication
    • Call EVM Function
    • Transact to EVM Function
      • Security
    • Shift Decimal
  • More Reading
    • Chain IDs
    • Startpoints
    • Midpoint EOAs
  • Get in Touch
    • Contact Links
Powered by GitBook
On this page
  • Overview
  • Setup
  • Midpoint

Was this helpful?

  1. Get Started
  2. Sample Midpoints

Automation: Ensure a function is called at regular intervals

PreviousData Bridge: Pass arbitrary messages between chainsNextVideos

Last updated 2 years ago

Was this helpful?

Overview

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

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 .

The chain-id

You can look up the chain-id for the chain you want to use here: Chain IDs

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 source so that contract can make a midpoint request.

{
  "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 Task to send the summary back to the contract.

{
  "transactToEvmFunctionTestnet": {
    "chainId": "5",
    "contractAddress": "0x83986ff4fbcaa2acf6092930fcebbe25583be452",
    "functionName": "heartbeat",
    "arguments": [
      {
        "name": "time",
        "datatype": "uint256",
        "value": "{{currentTime}}"
      }
    ]
  }
}

3. Define Path

We define our path file.

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

4. Publish Midpoint

$ midpoint publish

Wikipedia page for cron