I have a factory smart contract that is used to create child contracts. For each of these child contracts, I have a function that needs to be called continuously with an AutoTask. Is there any way that I can automatically create an AutoTasks for each of these child contracts? That way I would not need to manually create an AutoTask for every new child contract that is deployed. Thanks!
Hey @blanket1! Do you actually need one autotask per each contract, or would a single autotask that loops over all contracts do the trick? If so, my suggestion would be to do something like:
- Have a scheduled autotask that loads the list of contracts from a data source (you could use the key-value store here, just be mindful of its limitations!) and calls whatever function is needed on each of them
- Have a sentinel that monitors your factory contract for events on new child contracts created, and triggers another autotask whenever that happens
- Have the triggered autotask add the new child contract address to your data source (if you use key-value store, remember that all data is automatically shared across all autotasks)
hi, thanks for the reply. I am having some trouble getting the scheduled autotask to load my child contracts and call each of their functions. From my understanding, autotask is only able to execute one function at each interval. Hence, if lets say I have 3 child contracts, I would only be able to execute the function for one of the contracts at every interval and not for all 3 contract? Really appreciate the help!
@blanket1 Follow the first bulleted point above, that is the proper way to solve your problem unless you want to create autotasks for each child contract.
That's not accurate: your autotask can send multiple transactions on each run. Just make sure you don't await for the tx to be mined as part of the autotask (since the relayer takes care of that!), and you can send one tx to each of your three child contracts!
Awesome! Managed to fix my Autotask to do just that. Will get to points 2 and 3 shortly. Thank you for the help, really appreciate it!