0

I have been working on this dapp lately that allow users to create a product with an expiration date (don't mind the specifics of the app). Once expired, a call to a smart contract should be made (transaction) and the product state should be changed to "expired". The question is - how to manage this task scheduling? I thought about building a mechanism on my own using smart contracts and off-chain services (similar to how Chainlink's model works) but I keep stumbling upon the gas fees require to trigger my contract on expiration. I also tried to figure out Chainlink's Automation but:

  1. They don't have mocks to test locally
  2. They offer a UI to register the "Upkeep" (their brand for the scheduled job) while I need to do it programmatically.

Please advice.

P.S: I could do all of this off-chain using microservices and regular databases, but obviously this misses the whole point

2
  • Hey @eyalmen- clarification: is the trigger for the on-chain state chain coming from a backend or frontend? A common way to mock this is to manipulate time on your local dev network and then run checkUpkeep + performUpkeep via scripts etc. Have you tried that?
    – ZeusLawyer
    Commented Sep 14, 2023 at 7:02
  • Hey @ZeusLawyer and thanks for the reply! The product's data is kept on-chain including the expiration date (represented by uint). The trigger can't come from the frontend because it's in the browser and I can't control the user's session (turning on/off the app or computer). So, the time must be handled on the backend
    – eyalmen
    Commented Sep 14, 2023 at 7:23

1 Answer 1

0

@eyalmen, np happy to help.

For programmatically registering an "upkeep" check out these docs https://docs.chain.link/chainlink-automation/register-upkeep#register-an-upkeep-using-your-own-deployed-contract

does that do the trick for you?

And instead of mocking the contract, in your tests you can directly test the behaviour of your smart contract (rather than the entire networks interaction) by just

  1. calling checkUpkeep on your consumer contract programmaticly
  2. calling performUppeep and optionally passing in performData if any or 0x if not.

Thats how you'd simulate that your contract behaves correctly when automation runs on it. That way you're testing your code behaviour directly.

1
  • Thanks! I found that in the docs myself and it does the trick, but after some thoughts I realized I can do without the automation for now
    – eyalmen
    Commented Sep 15, 2023 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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