0

In looking at the Chainlink Keepers documentation, it says you can set up a time-based keeper, which allows it to call a function in your smart contract based on a CRON schedule.

When should we use this instead of the custom logic trigger? It doesn't require that our contract be keeper compatible, so it sounds like it may be easier to implement.

But does the function that the keepers will call have to be public, or is there a way to ensure only keepers can call the function? For example if I have a pickWinner() function that I want to run every hour, and don't want some random hacker invoking it early.

And is the time-based trigger more or less gas efficient, since it says it deploys a new CronUpkeep contract to manage the schedule?

1 Answer 1

0

You have 2 questions, first one is:

When should we use the time-based trigger instead of the custom logic trigger?

Time-based trigger is used in the scenario where some action should be executed based on time. For example, the function pickWinner() you want to run every hour.

There may be some other projects where users want to call some function periodically. Let's say you are a user of a DeFi protocol, and you want to call claim() to get your yields every hour and reinvest. In the case, you can create a time-based trigger and call the claim() per hour.

Your second question is:

Is there a way to ensure only keepers can call the function?

Yes, you have to write a whitelist for your function, because the consumer contract is not Keepers-compatible for time-based triggers.

The Keepers would create a CronUpkeep contract from the CronUpkeepFactory, you can check the details in official document. If you look into the CronUpKeep.sol in GitHub, you will find there are functions performUpKeep and checkUpkeep in the contract. The contract serves as a delegate to call your function, and you can write a whitelist based on the CronUpKeep address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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