How to work with Cron - Moralis

I am interested in understanding how to run cron jobs that can pull data from a blockchain or from an API into Moralis.

  • supported languages, sample tutorials… will all be of great help.


We are currently working on an API to query our full nodes directly. This should be ready shortly. There is a UI for job scheduling functionality in the Moralis Dashboard, however this is currently not working- so don’t use it (this will be fixed later). What you could do however once the API is live is run a simple node app on Heroku (or your provider of choice) and use node-cron to run a function that queries the API directly or runs a cloud function which uses the API then stores the query results in the Moralis DB.

If you just need something really simple that calls the API every 60 seconds you could even use setInterval and do it entirely in Cloud Code on Moralis. The following code is valid Cloud Function code… it’s possible to have variables and functions outside the Moralis.Cloud.define() calls.

A simple demo that logs a counter to the Dashboard logs every 3 seconds.

let timer;
let counter = 0;
let logger;

function tick() {
  counter += 1;"counter:" + counter);

Moralis.Cloud.define('startCounter', async (request) => {
    logger = Moralis.Cloud.getLogger();
    timer = setInterval(tick, 3000);

Moralis.Cloud.define('stopCounter', async (request) => {

Thanks, I’ll just have to wait for the job scheduling function on Moralis then.

Don’t wait. This is not a high priority bug right now. Run a node app locally for dev to get it working, can deploy it to Heroku if you need to… then can refactor later to use the Moralis job scheduler if it meets your needs.