2

how can i invoke pickVoters() each 5 minutes using react?

import React, { Component } from "react";
class Pick extends Component {
static async getInitialProps(props) {
const { address } = props.query;

const eVoting = new EVoting(address);



const accounts = await web3.eth.getAccounts();
await eVoting.methods.pickVoters().send({
  from: accounts[0],
});
return { address };
}
1
  • This isn't a question about Ethereum is about programming in javascript. For this type of question you can ask in StackOverflow.com.
    – Ismael
    Dec 3, 2021 at 5:24

2 Answers 2

3

There is a useful interface for this which lets you easily schedule these time-based cron jobs without having to write any smart contract code called "Gelato Ops". Disclaimer: I helped to build it :).

Check it out here:

https://app.gelato.network/

On there, you can just enter the smart contract address and function you want to execute and then select the time interval which should determine when this function should be executed, like so:

enter image description here

There is a tutorial on Gelato which you can follow which actually walks you through automating a particular function call every 5 minutes!

You can also have any other arbitrary condition trigger your smart contracts however, not only time.

2
  • It seems you are part of Gelato network. The site has a rule that if you use a link in the answer you should disclose your affiliation or it will be considered as spam and deleted.
    – Ismael
    Feb 25, 2022 at 5:34
  • @Ismael added disclaimer
    – Hilmar X
    Feb 26, 2022 at 18:43
3

You cannot set up cron jobs in Solidity. Actually, Ethereum as a whole does not natively support this kind of operation.

You have to use an automation protocol that runs on top of Ethereum, e.g. Gelato Network.

4
  • Since he asked "with React", I imagine he'd want something like setTimeout. But no idea really Sep 14, 2021 at 15:22
  • Yes, that could be the case. We need more details from OP. Sep 14, 2021 at 15:57
  • yes, i need some operation like "useEffect" using react , is that possible? Sep 14, 2021 at 21:31
  • OP stands for "original poster", which is you. You need to update the question body and provide more details. Sep 14, 2021 at 21:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.