Automatic function call

In my smart contract, I want to execute specific function automatically after certain time interval. function should execute without any specific invocation for every 5 minutes. Can anyone help me in this regard.

That’s a limitation of smart contracts: they cannot initiate new actions. This means that you need an externally owned account (ie a regular user address) to send a tx to your contract every five minutes. You have a few options for doing this:

  • You can use Defender Autotasks along with Relayers to code a snippet that is run every 5 minutes and sends a tx to your contract.

  • You can integrate with the Keeper network or the Chainlink Keeper network, where you provide a bounty for your function to be executed (only available every 5 minutes), so keepers (aka workers) in the network will execute it for you.

  • You can piggyback on other calls to your contract. If you think that your contract will be called often, and are not too strict about those 5 minutes, you can just call your function from every other public function in your contract (if it hasn’t been run for more than 5 minutes), and push the burden (and cost!) of execution to your users.

1 Like

Hi @spalladino ,
Thank you so much for your response.

Thanks for your Response @spalladino. I tried Defender Autotask, I get this kind of log, but it doesn’t impact my contract. can you help me to solve this issue?

The logs you see there depend on what you console.log during your script execution. If you can share the code here, we can help troubleshoot!

Thanks, @spalladino.It is working now, But I have another, for every autotask it consumes gas fees that are detected from a relayer address.

If your Autotask is sending transactions through a connected Relayer, then yes, the gas fees for paying for those txs will be deducted from your Relayer balance. Defender will send you an email to notify about low funds (<0.1) on the Relayer though, so you can top it up when needed.

Thanks @spalladino .

1 Like