Autotask HTTPs request

Hi everyone, was experimenting with the autotask and wanted to do a scheduled job that does an external https call to retrieve some price info and then - if certain conditions are met - trigger a smart contract call. Is there any template or example script available I could use to help get started?

1 Like

I don't know much about the autotask right now, but what if you do the checkings per each transaction or use service or cron jobs to schedule actions at a time on hosting server.

Hi @A_S ,

Our stock Autotask template shows how to make a call with a Relayer (note you will need to select a Relayer in the "Connect to a relayer" input):

const { Relayer } = require('defender-relay-client');

exports.handler = async function(credentials) {
  const relayer = new Relayer(credentials);

  const txRes = await relayer.sendTransaction({
    to: '0xc7464dbcA260A8faF033460622B23467Df5AEA42',
    value: 100,
    speed: 'fast',
    gasLimit: '21000',
  });

  console.log(txRes);
  return txRes.hash;
}

As far as making a HTTPS call, I would recommend using axios, which is included in the Autotask bundle and can be required at the top of the Autotask code.

Amazing, thank you @dan_oz for pointing me to that, much appreciated, will test it out!