Gelato Automate SDK
Automate your smart contracts using Automate SDK
Installation
yarn add @gelatonetwork/automate-sdk
or
npm install @gelatonetwork/automate-sdk
How to use?
- Import the Automate SDK into your project:
import { AutomateSDK } from "@gelatonetwork/automate-sdk";
- Check if Automate is deployed on your network:
import { isAutomateSupported } from "@gelatonetwork/automate-sdk";
if (!isAutomateSupported(chainId)) {
console.log(`Automate network not supported (${chainId})`);
return;
}
- Instantiate Automate using your signer:
const automate = new AutomateSDK(chainId, signer);
- Create an automation task:
interface CreateTaskOptions {
name: string;
execAddress: string;
execSelector: string;
execAbi?: string;
dedicatedMsgSender: boolean;
execData?: string;
resolverAddress?: string;
resolverData?: string;
resolverAbi?: string;
singleExec?: boolean;
web3FunctionHash?: string;
web3FunctionArgs?: { [key: string]: unknown };
useTreasury?: boolean;
trigger?:
| {
type: TriggerType.TIME;
interval: number;
start?: number;
}
| {
type: TriggerType.CRON;
cron: string;
};
| {
type: TriggerType.EVENT;
filter: {
address: string;
topics: Array<Array<string | null>>;
};
blockConfirmations: number;
};
|
{
type: TriggerType.BLOCK;
};
}
const params: CreateTaskOptions = {
name,
execAddress,
execSelector,
interval,
dedicatedMsgSender,
};
const { taskId, tx }: TaskTransaction = await automate.createTask(params);
await tx.wait();
console.log(`Task created, taskId: ${taskId} (tx hash: ${tx.hash})`);
- Retrieve all your tasks:
const activeTasks = await automate.getActiveTasks();
activeTasks.forEach((task: Task) => {
console.log(`- ${task.name} (${task.taskId})`);
});
- Rename a task:
await automate.renameTask(taskId, "Another Gelato name");
- Cancel a task:
const { taskId, tx }: TaskTransaction = await automate.cancelTask(taskId);
await tx.wait();
console.log(`Task canceled, taskId: ${taskId} (tx hash: ${tx.hash})`);
- Overriding gas settings:
If you need to override gas settings, you can pass an additional Overrides
object to createTask
& cancelTask
methods:
const params: CreateTaskOptions = {
name,
execAddress,
execSelector,
interval,
dedicatedMsgSender,
};
const overrides: Overrides = { gasLimit: 2000000 };
const tx: TaskTransaction = await automate.createTask(params, overrides);
- Whitelisting msg.sender of function:
If you enabled dedicatedMsgSender
, your task will be called via a dedicated msg.sender
which you can whitelist on your smart contract for extra security.
If dedicatedMsgSender
is set to false, msg.sender
of the task will be the Automate contract.
To fetch your dedicated msg.sender
:
const { address } = await automate.getDedicatedMsgSender();
console.log("Dedicated msg.sender: ", address);
Examples
Check out our tutorial repository automate-sdk-hello-world for more in-depth examples.