How to use the time-based trigger
The time-based trigger is a trigger that is executed at a specific time or at a specific interval. This trigger is useful when you want to automate a specific action on a schedule, such as once every week.
Create the automations client
First, create an instance of the Automations
client:
import { createAutomationClient } from '@rhinestone/automations-sdk'
const automationClient = createAutomationClient({
account: '0x...',
accountType: 'SAFE', // 'SAFE', 'KERNEL',
apiKey: 'YOUR_API_KEY',
accountInitCode: '0x',
network: 11155111,
validator: '0x...',
})
Create the automation details
Next, create the automation details:
const actions = [
{
type: 'static',
target: '0x503b54Ed1E62365F0c9e4caF1479623b08acbe77',
value: 100,
callData: '0x',
},
]
const maxNumberOfExecutions = 10
Here, the actions are an array of actions to make on behalf of the account. They can either be static, in which case all the calldata is pre-defined, or dynamic, in which case the calldata is generated by a call to a calldata builder service. The maxNumberOfExecutions
is the number of times the automation will be executed.
Create the time based trigger details
Next, create the time based trigger details:
const triggerData = {
cronExpression: '*/60 * * * * *',
startDate: new Date().getTime(),
}
Here, the cronExpression
is a cron expression that defines the schedule for the automation. The startDate
is the start date for the automation.
Create the automation
Finally, create the automation:
const automation = await automationClient.createAutomation({
type: 'time-based',
data: {
trigger: {
triggerData,
},
actions,
maxNumberOfExecutions,
},
})