The SDK is suitable when you need to integrate task creation into your development environment or automated scripts. It's also useful for complex setups that require conditional logic before task submission.
Use the automate-sdk to easily create a new task:
yarn install @gelatonetwork/automate-sdk
Typescript Functions are still in private beta, make sure to use the beta version of the automate-sdk to have access to it
Typescript Function
Import the sdk and create task, passing your typescript function CID & arguments:
If your task utilizes secrets, you can set them after the task has been created.
const web3Function = new Web3Function(chainId, deployer);
const secrets = {
API_KEY: "..." // Set your secret environment variables
}
await web3Function.secrets.set(secrts, taskId);
Solidity Function
Repeat the installation step as shown above, then import and instantiate the SDK:
const automate = new AutomateSDK(chainId, signer);
Use createTask to automate your function calls:
interface CreateTaskOptions {
name: string; // your task name
// Function to execute
execAddress: string; // address of your target smart contract
execSelector: string; // function selector to execute on your target smart contract
execAbi?: string; // ABI of your target smart contract
// Proxy caller
dedicatedMsgSender: boolean; // task will be called via a dedicated msg.sender which you can whitelist (recommended: true)
// Optional: Pre-defined / static target smart contract inputs
execData?: string; // exec call data
// Optional: Dynamic target smart contract inputs (using a resolver)
resolverAddress?: string; // resolver contract address
resolverData?: string; // resolver call data (encoded data with function selector)
resolverAbi?: string; // your resolver contract ABI
// Optional: Time based task params
interval?: number; // execution interval in seconds
startTime?: number; // start timestamp in seconds or 0 to start immediately (default: 0)
// Optional: Single execution task
singleExec?: boolean; // task cancels itself after 1 execution if true.
// Optional: Payment params
useTreasury?: boolean; // use false if your task is self-paying (default: true)
}
const params: CreateTaskOptions = {
name,
execAddress,
execSelector,
interval
};
const { taskId, tx }: TaskTransaction = await automate.createTask(params);
The CreateTaskOptions interface is used for configuring Automated Transactions with the same structure and options as defined above.
The only difference is you need to configure your automated transaction without the need for a checker function.
Example:
interface CreateTaskOptions {
name: string; // Name your task
execAddress: string; // Address of your target smart contract
execSelector: string; // Function selector to call on your target smart contract
execAbi?: string; // ABI of your target smart contract (optional)
execData?: string; // Call data for the function execution (optional)
}
Single Execution Task
If you want to have Gelato call your function only once. If so, set singleExec flag to true when calling createTask.